Jump to content


Photo

**SOLVED** die(mysql_error())


  • Please log in to reply
1 reply to this topic

#1 anatak

anatak
  • Members
  • PipPipPip
  • Advanced Member
  • 406 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 18 May 2006 - 10:32 PM

Hello

Is 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 run

I would like to have something like
$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;

this way I could include a meaning full instruction when there is an error.

thank you
anatak
takasi.8008@docomo.ne.jp
tourokum@0508.jp

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 18 May 2006 - 11:10 PM

You could do something like:
<?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;
}?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users