php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #30055 incorrect example
Submitted: 2004-09-10 18:48 UTC Modified: 2004-09-10 20:26 UTC
From: slick dot user at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
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: slick dot user at gmail dot com
New email:
PHP Version: OS:

 

 [2004-09-10 18:48 UTC] slick dot user at gmail dot com
Description:
------------
in the manual under mysql_field_name(), http://us2.php.net/manual/en/function.mysql-field-name.php.
Example 1 is incorrect, the if statement after mysql_connect will always run true and the die statement will always run.

Nick 


Reproduce code:
---------------
<?php
/* The users table consists of three fields:
 *  user_id
 *  username
 *  password.
 */
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$db_selected) {
   die('Could not set $dbname: ' . mysql_error());
}
$dbname = 'mydb';
$db_selected = mysql_select_db($dbname, $link);
if (!$db_selected) {
   die('Could not set $dbname: ' . mysql_error());
}
$res = mysql_query('select * from users', $link);

echo mysql_field_name($res, 0) . "\n";
echo mysql_field_name($res, 2);
?> 

Expected result:
----------------
The above code would produce:

Could not set :

The if was probably suppose to check $link, not $db_selected


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-10 20:26 UTC] tomsommer@php.net
This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make the PHP documentation better.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Aug 03 13:00:02 2025 UTC