Jump to content

Archived

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

anatak

**SOLVED** die(mysql_error())

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.