mysql_num_rows, resource id #

mysql_num_rows, resource id #

am 27.03.2008 14:43:04 von Richard Dunne

In my code below, I am trying to verify that the query is selecting data from both rows of my answers table. I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0. I can't figure out why its not returning 2 for the number of rows. It is not giving me any error msgs such as cannot connect.

Also can tell me where I can find documentation on resource id #, such as resource(5)?
DEFINE ("host","localhost");
DEFINE ("user","root");
DEFINE ("password","pasword");
DEFINE ("database","questions");

$connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() );

$dbConnect=mysql_select_db('questions',$connection);
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query("Select answer from answers where studentID='A123456789'") or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows;


?>


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: mysql_num_rows, resource id #

am 27.03.2008 15:06:08 von Evert Lammerts

Richard Dunne wrote:
> In my code below, I am trying to verify that the query is selecting data from both rows of my answers table. I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0. I can't figure out why its not returning 2 for the number of rows. It is not giving me any error msgs such as cannot connect.
>
> Also can tell me where I can find documentation on resource id #, such as resource(5)?
> > DEFINE ("host","localhost");
> DEFINE ("user","root");
> DEFINE ("password","pasword");
> DEFINE ("database","questions");
>
> $connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() );
>
> $dbConnect=mysql_select_db('questions',$connection);
> if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}
>
> $result = mysql_query("Select answer from answers where studentID='A123456789'") or die(mysql_error());
> $rows = mysql_num_rows($result);
> echo $rows;
>
>
> ?>
Still no luck then. Try selecting the DB without the connection parameter:

$dbConnect=mysql_select_db('questions');

And don't forget to set error_reporting(E_ALL) above your code.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Fwd: Re: mysql_num_rows, resource id #

am 27.03.2008 15:43:21 von Richard Dunne

--Boundary_(ID_yW5JH0QrNdkgV6UMVDm1dA)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT
Content-disposition: inline

This much is working:

ini_set('error_reporting',E_All);
DEFINE ("host","localhost");
DEFINE ("user","root");
DEFINE ("password","password");
DEFINE ("database","questions");

$connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() );

$dbConnect=mysql_select_db('questions');
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query("Select answer from answers where studentID='A123456789'") or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows . "\n";
$answer = mysql_fetch_row($result);
foreach($answer as $a)
{
echo $a;
}


?>
The output is
1
1
which is correct.

One small step at a time, hopefully forward.

Richard.

--Boundary_(ID_yW5JH0QrNdkgV6UMVDm1dA)
Content-type: message/rfc822
Content-disposition: inline

Return-path:
Return-path:
Received: from mail1.o2.ie (mail1.o2.ie [62.40.33.135])
by msgstore1.o2.ie (Sun ONE Messaging Server)
with ESMTP id <0JYE005EW787W7@msgstore1.o2.ie> for richarddunne1971@o2.ie;
Thu, 27 Mar 2008 14:07:21 +0000 (GMT)
Received: from ug-out-1314.google.com ([66.249.92.170])
by mail1.o2.ie (Sun ONE Messaging Server)
with ESMTP id <0JYE008TC76KFX50@mail1.o2.ie> for richarddunne1971@o2.ie
(ORCPT richarddunne1971@o2.ie); Thu, 27 Mar 2008 14:07:20 +0000 (GMT)
Received: by ug-out-1314.google.com with SMTP id c2so305193ugf.30 for
; Thu, 27 Mar 2008 07:06:20 -0700 (PDT)
Received: by 10.78.134.6 with SMTP id h6mr3132249hud.68.1206626772162; Thu,
27 Mar 2008 07:06:12 -0700 (PDT)
Received: from ?192.168.1.109? ( [89.134.206.226]) by mx.google.com with ESMTPS
id f31sm472212fkf.15.2008.03.27.07.06.10 (version=TLSv1/SSLv3 cipher=RC4-MD5)
; Thu, 27 Mar 2008 07:06:11 -0700 (PDT)
Date: Thu, 27 Mar 2008 15:06:08 +0100
From: Evert Lammerts
Subject: Re: [PHP-DB] mysql_num_rows, resource id #
In-reply-to: <13cda813da48.13da4813cda8@o2.ie>
To: Richard Dunne
Cc: php-db@lists.php.net
Message-id: <47EBA9D0.8050803@gmail.com>
MIME-version: 1.0
Content-type: text/plain; format=flowed; charset=ISO-8859-1
Content-transfer-encoding: 7BIT
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com;
s=beta;
h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-t o:content-type:content-transfer-encoding;
bh=Yga1QBZKSBz8jFg7BKp8Pcq3WlGE3eE1flGAXmdhwGw=;
b=HV4X2TZVsZooGH3tTGvCPl6P20kOz+BTPBxeBdm7LJSLAcmYokravAZW8O KnX6oKB/1EYd5HRldI3D0D62I0H/JzhgZsW67luX8PEv+KJEF9mUSGsjHCdX jTQtjicEgFArjX9ZQnDXKraOCXJav5he1t/C3ks/QfAWDJ9xhJBtM=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta;
h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encodi ng;
b=jxoBgwWmOo6NRbYOjqhc+T9nVN5BMuED0/sE72fcKgZrxKWEOfQ/OS05qW lMSN81jd87YrT2JD1S8DY5Hn35uYGEqiibDhF3+Ez0lniYFK3fDusjDlIRBA 8xODi1IL5CjGSipEGO0c34vRBsOOngaBx2QIO7hxFHuZBRkluuPuM=
References: <13cda813da48.13da4813cda8@o2.ie>
User-Agent: Thunderbird 2.0.0.6 (X11/20071022)
Original-recipient: rfc822;richarddunne1971@o2.ie

Richard Dunne wrote:
> In my code below, I am trying to verify that the query is selecting data from both rows of my answers table. I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0. I can't figure out why its not returning 2 for the number of rows. It is not giving me any error msgs such as cannot connect.
>
> Also can tell me where I can find documentation on resource id #, such as resource(5)?
> > DEFINE ("host","localhost");
> DEFINE ("user","root");
> DEFINE ("password","pasword");
> DEFINE ("database","questions");
>
> $connection=mysql_connect(host,user,password) or die ('Could not connect' . mysql_error() );
>
> $dbConnect=mysql_select_db('questions',$connection);
> if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}
>
> $result = mysql_query("Select answer from answers where studentID='A123456789'") or die(mysql_error());
> $rows = mysql_num_rows($result);
> echo $rows;
>
>
> ?>
Still no luck then. Try selecting the DB without the connection parameter:

$dbConnect=mysql_select_db('questions');

And don't forget to set error_reporting(E_ALL) above your code.


--Boundary_(ID_yW5JH0QrNdkgV6UMVDm1dA)
Content-Type: text/plain; charset=us-ascii

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--Boundary_(ID_yW5JH0QrNdkgV6UMVDm1dA)--