?
Solved

display mysql error message

Posted on 2009-02-16
13
Medium Priority
?
1,012 Views
Last Modified: 2012-05-06
Hello,
I need help in this , I cannot see mysql error message , I don't know where to look??
Thanks

php.ini
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
error_reporting  =  E_ALL & ~E_NOTICE
display_errors = On
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
 
 
insert code
***********************
 
$query	= "INSERT INTO history(web_serial, browser, date, ip) ".
  "VALUES(".$row["web_serial"].", '".$row["browser"]."', '".$row["date"]."', '".$row["ip"].";
$result	= mysql_query($query, $link);
if (!$result){
	echo "<B>Erorrr .</B>". mysql_error() ."<BR/>";
}

Open in new window

0
Comment
Question by:rim2009
  • 8
  • 5
13 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23654353

if (!$result)
{
   $errno = mysql_errno();
   $error = mysql_error();
   echo "<br/><br/>QUERY FAIL: $query \n";
   echo "<br/>$errno $error \n";
}

Open in new window

0
 

Author Comment

by:rim2009
ID: 23654457
it return only the $query without any $errno or $error
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23654472
Please post the complete code.  There is something conditional that is wrong and it's not shown in the code snippet.  Thanks, ~Ray
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rim2009
ID: 23654563

$query	= "SELECT * FROM gdata WHERE date = '$dateP' ORDER BY date ASC";
$res	= mysql_query($query, $mlink);
while ($row = mysql_fetch_array($res))
{
$query	= "INSERT INTO history(web_serial, browser, date, ip) ".
  "VALUES(".$row["web_serial"].", '".$row["browser"]."', '".$row["date"]."', '".$row["ip"].";
$result	= mysql_query($query, $link);
if (!$result){
   $errno = mysql_errno();
   $error = mysql_error();
   echo "<br/><br/>QUERY FAIL: $query \n";
   echo "<br/>$errno $error \n";
}
}

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23654974
One query looks at $mlink and the other looks at $link.  Could that matter?

Try replacing with this:

Best regards, ~Ray
$query  = "SELECT * FROM gdata WHERE date = '$dateP' ORDER BY date ASC";
$res    = mysql_query($query, $mlink);
if (!$res){
   $errno = mysql_errno();
   $error = mysql_error();
   echo "<br/><br/>QUERY FAIL: $query \n";
   echo "<br/>$errno $error \n";
}
 
while ($row = mysql_fetch_array($res))
{
   $query  = "INSERT INTO history(web_serial, browser, date, ip) ".
     "VALUES(".$row["web_serial"].", '".$row["browser"]."', '".$row["date"]."', '".$row["ip"].";
   $result = mysql_query($query, $link);
   if (!$result){
      $errno = mysql_errno();
      $error = mysql_error();
      echo "<br/><br/>QUERY FAIL: $query \n";
      echo "<br/>$errno $error \n";
   }
}

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23655037
Run this and see what you get.  The missing error messages are probably because the query used a non-existent link field.  When the link field is omitted, mysql uses the last valid connection, and the query is attempted.  It fails and you get the correct error message.
<?php // RAY_mysql_err.php
 
// NO DATA BASE CONNECTION IS SURE TO CAUSE AN ERROR
 
$query  = "SELECT shit FROM shinola";
$res    = mysql_query($query);
if (!$res)
{
   $errno = mysql_errno();
   $error = mysql_error();
   echo "<br/><br/>QUERY FAIL: $query \n";
   echo "<br/>$errno $error \n";
}

Open in new window

0
 

Author Comment

by:rim2009
ID: 23659492
try to use the select statment I posted before instead of using select shit
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23659567
@rim2009: The point of the example is to deliberately produce an error, so you can see what it looks like.  MySQL is not all that great about error messages.

The problem that is causing your error messages to not show up is NOT the query string.  Please see my earlier post, where I wrote:

The missing error messages are probably because the query used a non-existent link field.  When the link field is omitted, mysql uses the last valid connection, and the query is attempted.  It fails and you get the correct error message.

Please see the code snippet.  Thanks, ~Ray
// WHAT IS THE MEANING OF $mlink?  HAVE YOU PRINTED IT OUT WITH var_dump() TO BE SURE IT IS CORRECT?
mysql_query($query, $mlink);
 
 
// TRY THE QUERY THIS WAY
mysql_query($query);

Open in new window

0
 

Author Comment

by:rim2009
ID: 23659717
$mlink iis link to the remote machine
$link is link to my localhost
I read from the remote machine and write in my localhost
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23659772
Please use var_dump() to print out both of those variables and post the results here, thanks.  Place the var_dump($mlink) [ or var_dump($link) ] immediately before the mysql_query() statement.  We want to make sure that both of these are correctly connected to the appropriate mysql data base.
0
 

Author Comment

by:rim2009
ID: 23660475
the output for var_dump()
$mlink : resource(4) of type (mysql link)
$link : resource(2) of type (mysql link)
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 23660659
Great, that's helpful.  About the link identifier, the man page says:

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.

That is a sure recipe for confusion when you're using two separate connections!

So let's try putting the correct link identifier into the mysql_errXX() functions like this:

mysql_errno($mlink) - or mysql_errno($link) -- depending on what was queried last.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 23661840
Thanks for the points.  This is a great question because the way MySQL handles these error functions is really counterintuitive.  Glad we found a solution! ~Ray
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question