問題を再現できません。
<?php
define('QUERY', 'select * from tableA inner join tableB on tableB.id=tableA.id');
$pdo = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'localonly', 'localonly');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
setup($pdo);
echo PHP_VERSION, "\n";
echo 'client: ', $pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), "\n";
echo 'server: ', $pdo->getAttribute(PDO::ATTR_SERVER_VERSION), "\n";
foreach($pdo->query(QUERY, PDO::FETCH_ASSOC) as $row) {
print_r($row);
}
function setup(PDO $pdo) {
$pdo->exec('
CREATE TEMPORARY TABLE tableA (
id int,
name varchar(16),
gender int,
key(id)
)
');
$pdo->exec('
CREATE TEMPORARY TABLE tableB (
id int,
name varchar(16),
salary int,
key(id)
)
');
$pdo->exec("INSERT INTO tableA (id,name,gender) VALUES (1, 'nA', 1), (2, 'nb', 1), (3, 'nc', 1), (4, 'nd', 1)");
$pdo->exec("INSERT INTO tableB (id,name,salary) VALUES (1, 'nA', 1), (2, 'nb', 4), (3, 'nc', 9), (4, 'nd', 16)");
}
プリント
5.3.8
client: mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $
server: 5.5.16
Array
(
[id] => 1
[name] => nA
[gender] => 1
[salary] => 1
)
Array
(
[id] => 2
[name] => nb
[gender] => 1
[salary] => 4
)
Array
(
[id] => 3
[name] => nc
[gender] => 1
[salary] => 9
)
Array
(
[id] => 4
[name] => nd
[gender] => 1
[salary] => 16
)
(予想通り)。
内部に代わって結合を試みる – OptimusCrime
@OptimusCrime:なぜですか?この場合の説明は何でしょうか? – VolkerK
名前?何という名前? table_a.nameまたはtable_b.name? –