php - simple select returns unexpected result -
running code returns unexpected result
<?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 * test'); if($s->execute()){ var_dump($s->fetchall()); } $s = $pdo->prepare('select * test id = ?'); if($s->execute(array(1))){ var_dump($s->fetchall()); } }catch(exception $e){ echo $e->xdebug_message; }
returns
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 ', ), )
as can see second statement fails
(note i'm running gentoo linux 64, , i'm connecting sql server 2012 on win7 64 virtual machine)
i second statement using mysql. may need free connection server between statements using closecursor using sql server.
$pdo = new pdo('odbc:driver={sql server native client 11.0};server=192.168.178.11;database=test;','sa', 'secret'); $s = $pdo->prepare('select * test'); if($s->execute()){ var_dump($s->fetch()); } $s->closecursor();// add sql server $s = $pdo->prepare('select * test id = ?'); if($s->execute(array(1))){ var_dump($s->fetch());
ps fetch()
fetches 1 row. should have 1 id in var_dump()
Comments
Post a Comment