php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #25138 mysql_connect example
Submitted: 2003-08-18 21:26 UTC Modified: 2003-08-19 07:01 UTC
From: curt at zirzow dot dyndns dot org Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 - 37 = ?
Subscribe to this entry?

 
 [2003-08-18 21:26 UTC] curt at zirzow dot dyndns dot org
Description:
------------
mysql_connect: example 1:
<?php
    $link = mysql_connect("localhost", "mysql_user", "mysql_password")
        or die("Could not connect: " . mysql_error());
    print ("Connected successfully");
    mysql_close($link);
?>

mysql_error() will not give a reason why the connect failed, according to:

http://bugs.php.net/bug.php?id=24689

php4 will never give that message but php5 will. I havn't tested to see if this is true for php5.

An alternative is to use $php_errormsg, but that can only used if php_ini.track_errors is set.

Related Issues:
Reason this occurs [closed]

mysql_error() documentation [closed]
http://bugs.php.net/bug.php?id=20743

Thanks,
Curt


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-19 07:01 UTC] didou@php.net
Actually it works.

didou@tunis:/$ php -v
4.2.3
didou@tunis:/$ php
<?php

error_reporting(0);

mysql_connect('localhost','root','foo') or die("I'm dead :: " . mysql_error() . "\n");

?>

output :

I'm dead :: Access denied for user: 'root@localhost' (Using password: YES)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 08:01:28 2024 UTC