Jump to content

**SOLVED** die(mysql_error())


anatak

Recommended Posts

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
[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 you
anatak
Link to comment
https://forums.phpfreaks.com/topic/9956-solved-diemysql_error/
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/9956-solved-diemysql_error/#findComment-37023
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.