Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.