View Single Post

  #2 (permalink)  
Old 10-07-2006
Ron Barnett
 
Posts: n/a
Default Re: Error Trapping Database Activity


"Simon Harris" <too-much-spam@makes-you-fat.com> wrote in message
news:CeKVg.2797$pa.1391@newsfe2-gui.ntli.net...
> Hi All,
>
> Can anyone advise me how to trap errors when carrying out database
> inserts/updates/deletes (Queries that do not return any rows).
>
> Here is my code:
>
> $query = "some sql statement;";
> mysql_query($query);
>
> At present, this is executing (Or appears to be!) but the database is
> uneffected. I guess I need some sort of return value from mySQL so I can
> tell my users that the update/whatever happened OK.
>
> Thanks!
> Simon.
>

here is a snip from the PHP manual on the php.net website

Example 1. mysql_error() example

<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");

mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";

mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>


If you check mysql_error() and/or mysql_erno() you should get an idea of
what is or isn't going on.
You don't actually need to pass the link to these functions unless you have
multiple databases open as it will default to the last session anyway.

Cheers

Ron


Reply With Quote