By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,722 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,722 IT Pros & Developers. It's quick & easy.

error checking in php?

P: n/a
Hi all!

If I have

$result=odbc_exec($conn, $sql2);
while(odbc_fetch_row($result))

Then I'd like to check for errors on the first line, so I can catch the
error and handle it myself?

Like the delphi:

try
$result=odbc_exec($conn, $sql2);
$error=false;
except
$error=true;
end
while( !$error && odbc_fetch_row($result) )

BR
Sonnich

Jan 18 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sonnich wrote:
try
$result=odbc_exec($conn, $sql2);
$error=false;
except
$error=true;
end
while( !$error && odbc_fetch_row($result) )
Take a look at PDO. It's the new PHP 5 way of accessing databases, using a
unified syntax for all database engines (no need to worry about
mysql_query vs pg_query vs odbc_exec!)

*And* it uses Exceptions which can be handled pretty much like you
describe.

<?php
try
{
$db = new PDO ($connection_string, $username, $password);
$result = $db->query($sql_query);
foreach ($result as $row)
{
/* Do something */
}
}
catch (Exception $e)
{
print "Something bad happened", $e, "\n";
}
?>

You like?

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 18 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.