anatak Posted May 18, 2006 Share Posted May 18, 2006 HelloIs it possible to get the mysql erro() in a variable if for some reason the query fails ?now I have$Result = mysql_query($Query) or die(mysql_error());but this means that the error is printed when the statement is runI would like to have something like[code]$query="select * from users where UserId=01;";read_connection();$Result = mysql_query($Query) or die(mysql_error());read_close();if (gettype($Result)== 'string'){ echo "<br />string: ".$Result;}else{ echo "<br />resource: ".$Result;[/code]this way I could include a meaning full instruction when there is an error.thank youanatak Quote Link to comment https://forums.phpfreaks.com/topic/9956-solved-diemysql_error/ Share on other sites More sharing options...
kenrbnsn Posted May 18, 2006 Share Posted May 18, 2006 You could do something like:[code]<?php$query="select * from users where UserId=01;";read_connection();$Result = mysql_query($Query)if (!$Result) $Result = mysql_error();read_close();if (gettype($Result)== 'string'){ echo "<br />string: ".$Result;}else{ echo "<br />resource: ".$Result;}?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/9956-solved-diemysql_error/#findComment-37023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.