This is a discussion on Error Trapping Database Activity within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All, Can anyone advise me how to trap errors when carrying out database inserts/updates/deletes (Queries that do ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. -- - * Please reply to group for the benefit of all * Found the answer to your own question? Post it! * Get a useful reply to one of your posts?...post an answer to another one * Search first, post later : http://www.google.co.uk/groups * Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat! -------------------------------------------------------------------------------- I am using the free version of SPAMfighter for private users. It has removed 10157 spam emails to date. Paying users do not have this message in their emails. Try SPAMfighter for free now! |
|
|||
|
"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 |
|
|||
|
> 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. Great, thanks! :-) -------------------------------------------------------------------------------- I am using the free version of SPAMfighter for private users. It has removed 10158 spam emails to date. Paying users do not have this message in their emails. Try SPAMfighter for free now! |
|
|||
|
"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. > > -- > - > * Please reply to group for the benefit of all > * Found the answer to your own question? Post it! > * Get a useful reply to one of your posts?...post an answer to another one > * Search first, post later : http://www.google.co.uk/groups > * Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat! > > -------------------------------------------------------------------------------- > I am using the free version of SPAMfighter for private users. > It has removed 10157 spam emails to date. > Paying users do not have this message in their emails. > Try SPAMfighter for free now! > > Hi Simon, mysql_query will return FASLE on error, so if you just need a simple check to see if the query suceeded something like this should do it if (mysql_query($query)) { //OK } else { //handle error } cheers ED |
|
|||
|
On Sat, 07 Oct 2006 09:15:14 GMT, "Simon Harris" <too-much-spam@makes-you-fat.com> wrote:
>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. $sql = "SELECT * FROM table"; $qry = mysql_query($sq) or die(mysql_error()); if( mysql_num_rows($qry)==0 ) echo " No data fool"; else{ while( $row=mysql_fetch_assoc($qry) ){ $someData = stripslashes($row['whatever']); echo "$someData<br />\n"; } } |
![]() |
| Thread Tools | |
| Display Modes | |
|
|