php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10291 Calling mysql_error() after mysql_connect() does not return the error
Submitted: 2001-04-11 13:10 UTC Modified: 2001-04-11 16:39 UTC
From: mfischer at josefine dot ben dot tuwien dot ac dot at Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0 Latest CVS (11/04/2001) OS: Linux / Debian unstable
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mfischer at josefine dot ben dot tuwien dot ac dot at
New email:
PHP Version: OS:

 

 [2001-04-11 13:10 UTC] mfischer at josefine dot ben dot tuwien dot ac dot at
When connecting to a mysql database with the following code :

$link = @mysql_connect( 'localhost:/wrong/socket/path', 'user', 'pass');

if( $link == false) {
	echo "\nerror # ".mysql_errno()." ".mysql_error()."\n";
	exit;
}

PHP of course is unable to successfully connect. PHP fires a warning
message that the socket path couldn't be found:

MySQL Connection Failed: Can't connect to local MySQL server through socket

When using @mysql_connect the warning is does not appear, but
its impossible to retrieve the exact error within PHP. mysql_errno() and
mysql_error() do not return any information (empty ).

Normally on websites, a user doesn't care about the exact error message. But
when writing client side Applications (e.g. php-gtk), a call to PHP's
mysql_error() or mysql_errno() after mysql_connect() should really return the
right message from libmysql.


Looking at the current CVS, line 579 in ext/mysql/php_mysql.c retrieves the
mysql_error() and fires it as a warning to the user.

Since in line 581 the *mysql structure gets freed, Its clear for me that
a call in PHP after mysql_connect cannot retrieve this error.

Are there any workarounds possible ? Its not a high priority problem of course
but seriously to take I guess ?

thanks,
	Markus

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-11 14:01 UTC] mfischer at josefine dot ben dot tuwien dot ac dot at
Maybe I should add that I've actually also read closed bug report # 2051 about that topic.

Zeev answered that in this situation mysql_error() never has and doesn't return error information for failed connections.

But libmysql is returning the right (and indeed very
descriptive) error message.

I hope the upcoming demand for client side php application convinces Zeev.

 [2001-04-11 16:39 UTC] mfischer at josefine dot ben dot tuwien dot ac dot at
I was convinced its stupid to change this because there
would be no clean way to implement this.

thx anyway, keep on good PHP working

markus

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 22:01:27 2025 UTC