Date: 12/28/00
- Next message: Andy Etemadi: "Re: [PHP-DB] IBM DB2 and DSN"
- Previous message: john slee: "Re: [PHP-DB] 'Best' DB for Linux/Apache/PHP?"
- In reply to: Christoph Ender: "[PHP-DB] No mysql_error() from mysql_connect()"
- Next in thread: Stuart McDonald: "[PHP-DB] Counting time in a stats table"
- Reply: Stuart McDonald: "[PHP-DB] Counting time in a stats table"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 11:46 PM +0100 12/28/00, Christoph Ender wrote:
>Hi,
>
>When trying to connect to a MySQL Database, I try catch errors with
>mysql_error(). That works fine, but not for mysql_connect().
That's right. mysql_error() and mysql_errno() cannot report errors
properly until a valid connection has been established. That means
they're useless for reporting errors that occur during the connection
attempt. Try printing the value of $php_errormsg instead:
# Demonstrate error-checking with mysql_error() and mysql_errno().
# This also handles mysql_connect(), for which mysql_error() and
# mysql_errno() don't work. Use of $php_errormsg assumes that
# you have track_errors turned on in your PHP configuration file.
#@ FRAG
if (!($conn_id = <email protected> ("host", "user", "password")))
{
die ("Cannot connect to database server: "
. htmlspecialchars ($php_errormsg) . "\n");
}
>
>Example:
>
>------------------------------------------------------------------------
><?php
>$linkid = mysql_connect("localhost", "myusername", "mypassword");
>echo mysql_errno().": ".mysql_error()."<BR>";
>?>
>------------------------------------------------------------------------
>
>returns the following:
>
>------------------------------------------------------------------------
>Warning: MySQL Connection Failed: Can't connect to local MySQL server
>through socket '/var/lib/mysql/mysql.sock' (111) in
>/usr/local/httpd/htdocs/ModernMarket/t1.php3 on line 3
>:
>------------------------------------------------------------------------
>
>So just a single colon, no messages. Turning off the warnings like this...
>
>------------------------------------------------------------------------
><?php
>$old_error_reporting = error_reporting(E_ALL & ~(E_WARNING ));
>
>$linkid = mysql_connect("localhost", "myusername", "mypassword");
>echo mysql_errno().": ".mysql_error()."<BR>";
>
>error_reporting($old_error_reporting);
>?>
>------------------------------------------------------------------------
>
>... leaves me just with a colon. I can test for a valid database
>connection with "if ($link) ..." but I'd like to catch the mysql error
>that caused the connection-failure.
>
>Any ideas? Someone succeeded here?
>
>Thanks in advance,
>Christoph.
>
>
>--
>Christoph Ender
>chrender <email protected>
>http://www.moondock.org/chrender/
>
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-db-unsubscribe <email protected>
>For additional commands, e-mail: php-db-help <email protected>
>To contact the list administrators, e-mail: php-list-admin <email protected>
-- Paul DuBois, paul <email protected>-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe <email protected> For additional commands, e-mail: php-db-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Andy Etemadi: "Re: [PHP-DB] IBM DB2 and DSN"
- Previous message: john slee: "Re: [PHP-DB] 'Best' DB for Linux/Apache/PHP?"
- In reply to: Christoph Ender: "[PHP-DB] No mysql_error() from mysql_connect()"
- Next in thread: Stuart McDonald: "[PHP-DB] Counting time in a stats table"
- Reply: Stuart McDonald: "[PHP-DB] Counting time in a stats table"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

