Thursday, 15 March 2012

php - hidding errors when sqlsrv_fetch_array return nothing -



php - hidding errors when sqlsrv_fetch_array return nothing -

i reading records db. when query fail have errors exmp : undefined variable. know thats normal becouse query cant find nil in db. how hide errors? trying this:

$result = sqlsrv_query($conn, "my sql query status='running'))"); if ($result === false) { $note = 'unknown'; $code = 'unknown'; } else { while($row = sqlsrv_fetch_array($result)) { $note = $row['note']; $code = $row['code']; } } echo $note; echo $code;

logicly should good?

if there no results $result not false there no rows. can round setting $note , $code variables default first:

$result = sqlsrv_query($conn, "my sql query status='running'))"); $note = 'unknown'; $code = 'unknown'; if ($result !== false) { while($row = sqlsrv_fetch_array($result)) { $note = $row['note']; $code = $row['code']; } } echo $note; echo $code;

php sql sql-server database

No comments:

Post a Comment