PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #10341 mysql_fetch_object, $row->0 produces parse error
Submitted:15 Apr 2001 8:26pm UTC Modified: 16 Apr 2001 3:54am UTC
From:francis at wpi dot edu Assigned to:
Status:Closed Category:MySQL related
Version:4.0.4pl1 OS:Win 2000
View/Vote Developer Edit Submission

Welcome! If you don't have a SVN account, you can't do anything here. You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
SVN Username: SVN Password:
Quick Fix:
Status: Assign to:
Category:
Summary:
From: francis at wpi dot edu
New email:
Version: OS:
New/Additional Comment:

[15 Apr 2001 8:26pm UTC] francis at wpi dot edu
The script:

mysql_pconnect ($dbhost, $dbuser, $dbpass);
$result = mysql_db_query ("database", "select * from tablename");
while ($row = mysql_fetch_object ($result, MYSQL_NUM)) {
    echo $row->0;
    echo $row->1;
}
mysql_free_result ($result);

Generates the error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{''
or `'$'' in d:/htdocs/assets/includes/hs~form_functions.php on line 31

The script below works but not for the general case (different column
names):

mysql_pconnect ($dbhost, $dbuser, $dbpass);
$result = mysql_db_query ("database", "select * from tablename");
while ($row = mysql_fetch_object ($result, MYSQL_ASSOC)) {
    echo $row->columnone;
    echo $row->columntwo;
}
mysql_free_result ($result);
[16 Apr 2001 3:54am UTC] mathieu@php.net
You're using mysql_fetch_object(). This function
returns an object where its members are named after its corresponding
column names.

CREATE TABLE test (
id int4,
name varchar(20) );

Using this table, you would use the following code to
retrieve its data:

$row_obj = mysql_fetch_object($qry_result);
echo $row_obj->name . ' (' . $row_obj->id . ')';

If you want to use numbers to access the columns please use
mysql_fetch_row().

And please, do take a closer look at that manual.

-- Mathieu

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC