このコードを実行すると、予期しない結果が返されます
<?php
error_reporting(-1);
try{
$pdo = new PDO('odbc:Driver={SQL Server Native Client 11.0};Server=192.168.178.11;Database=test;','sa', 'secret');
$s = $pdo->prepare('SELECT * FROM test');
if($s->execute()){
var_dump($s->fetchAll());
}
$s = $pdo->prepare('SELECT * FROM test WHERE id = ?');
if($s->execute(array(1))){
var_dump($s->fetchAll());
}
}catch(Exception $e){
echo $e->xdebug_message;
}
戻り値
array (
0 =>
array (
'id' => '1',
0 => '1',
'test' => 'test ',
1 => 'test ',
),
1 =>
array (
'id' => '2',
0 => '2',
'test' => 'test2 ',
1 => 'test2 ',
),
2 =>
array (
'id' => '3',
0 => '3',
'test' => 't3 ',
1 => 't3 ',
),
)
ご覧のとおり、2番目のステートメントは失敗します
(私はgentoo linux 64を実行していて、win7 64仮想マシンでSQLサーバー2012に接続していることに注意してください)