Mailing List Archive



Back to the month index Back to the list index

ahodgson@simkin.com
Tue, 1 Apr 1997 10:07:00 -0800 (PST)


From: ahodgson@simkin.com
Message-Id: <19970401180700.23664.qmail@skynet.simkin.com>
Subject: Re: [mSQL] How to use msqlQuery ( ) and msqlStoreResult ( )
Date: Tue, 1 Apr 1997 10:07:00 -0800 (PST)

-----BEGIN PGP SIGNED MESSAGE-----

> The docs show an example:

> if (msqlQuery($sock, "select * from foo") < 0)
> {
> echo("ERROR : $ERRMSG\n");
> }

> Which appears to require a:

> $res = msqlStoreResult();

> to actually store the query result(s) in a variable. What kind of
> a variable is $res??? The docs show it as an "int" and I don't
> understand how that can how an array of results, or even a
> character string.

It's a pointer to a result structure. The result structure itself is only
accessible through the API functions.

> If I have a table with multiple rows and columns of data, how can I access
> the other columns of data?

> Could someone please explain the msqlFetchRow ( ), msqlStoreResult ( ),
> and msqlStoreResult ( ) function interactions???

Sure,

msqlQuery($sock,"select field1,field2,field3 from table1 where field4 =
'some value'");

/* Store query results */
$msresult = msqlStoreResult();

/* See if we got anything */
if (msqlNumRows($msresult)>0)
{
        $counter = 1;
        /* Step through results */
        while ($counter <= msqlNumRows($msresult))
        {
                /* Store next row into array $row */

                $row = msqlFetchRow($msresult);

                printf("Field1 of row %d = %s\n",$counter,$row[0]);
                printf("Field2 of row %d = %s\n",$counter,$row[1]);
                printf("Field3 of row %d = %s\n",$counter,$row[2]);

                $counter++;
        }
}
msqlFreeResult($msresult);

Simple, huh?

- - Alan

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: noconv

iQBFAwUBM0FOw97xIGpYKU9lAQG2VgGAmf4mEOnVu/iQqGoYVsTJjR4T4ViBUaKp
stA2AG5ruZQi8EtpLbQdAN4CttueNugl
=pSol
-----END PGP SIGNATURE-----
--------------------------------------------------------------------------
To remove yourself from the Mini SQL mailing list send a message containing
"unsubscribe" to "unsubscribe" to msql-list-request@bunyip.com. Send a message containing
"info msql-list" to majordomo@bunyip.com for info on monthly archives of
the list. For more help, mail owner-msql-list@bunyip.com NOT the msql-list!