php - PDO dblib not catching warnings -
i have made symfony app connect mssql database using realestateconz/mssql-bundle , free tds.
my problem when try execute stored procedure, procedure throws exception if goes wrong, pdo reports nothing back.
if same thing using mssql_* functions warning correct error message mssql.
what pdo doing differently?
here 2 samples of code;
//pdo version try { $conn = new pdo($dsn, $user, $pass); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); } catch (pdoexception $e) { var_dump($e->getmessage()); die; } $stmt = $conn->prepare("insert importex_parteneri (id_importex, cif_cnp, denumire) values (1, 9671891, 'nexus media')"); $result = $stmt->execute(); var_dump($result); //true $stmt = $conn->prepare("exec dbo.importex_parteneri_exec 1"); $result = $stmt->execute(); var_dump($result); //true
the mssql_* example
$connection = mssql_connect($server, $user , $pass); mssql_select_db($nexus_bazadate, $connection); $result = mssql_query("insert importex_parteneri (id_importex, cif_cnp, denumire) values (1, 9671891, 'nexus media')"); var_dump($result); $result = mssql_query("exec dbo.importex_parteneri_exec 1"); var_dump($result); /* * output * * bool(true) php warning: mssql_query(): message: error 50000, level 16, state 1, procedure importex_parteneri_exec, line 181, message: prt012 - eroare import par9671891 (severity 16) in /home/vagrant/cv.dev/web/test.php on line 19 php warning: mssql_query(): general sql server error: check messages sql server (severity 16) in /home/vagrant/cv.dev/web/test.php on line 19 bool(true) */
solution i ended adding wraper around pdo::execute function function
execute(\pdostatement $stmt, array $params = array()) { $result = $stmt->execute($params); $err = $stmt->errorinfo(); switch ($err[0]) { case '00000': case '01000': return true; default: //case hy000 return false; } }
i may wrong don't recall seeing native way handle sql warnings in pdo in somehow automated way. according user comment can test manually sqlstate error code , it'll be:
'00000'
(success)'01000'
(success warning)
if works, it's of course annoying hand. if have custom layer on top of pdo can in custom exec method.
Comments
Post a Comment