Using the PurePHP MySQL API Result Set
Using the PurePHP MySQL API – Part 4
Foreword: In this part of the series, I show you the basics on accessing the PurePHP MySQL API result set.
By: Chrysanthus Date Published: 17 Jan 2018
Introduction
Remember, you begin your script that will use the API with:
require_once("./Mysql.php");
or similar statement.
The $Result Array Variable
The variable, $Result holds an array. It has the result set. To access the array rows from your script the syntax is,
$Result[$row_no]
Row number ($row_no) counting begins from zero (not 1).
This array is actually an index array of associative arrays. To refer to the array alone, you would type:
$Result
To refer to each row (of associative array) the syntax is:
$Result[$row_no]
which returns a reference to the associative array that forms the row.
To access a cell value of the result set, the syntax is:
$Result[$row_no]['column_name']
where column-name is the name of the column of the result set.
You need a for-loop to read the contents of a number of rows of the result set. Before that you should know the maximum number of rows that have been sent by the server. This is stored in the scalar variable, $No_of_Rows in the Mysql module. It is accessible similarly to the above as,
$No_of_Rows
In your script, you can print out the number of rows to the browser with:
echo $No_of_Rows;
If you want to read all contents of all the rows, of the table we are dealing with in this series, and print to the web page (browser), your for-loop would be like:
for ($i=0; $i<$No_of_Rows; ++$i)
{
echo $Result[$i]['name'], ', ';
echo $Result[$i]['owner'], ', ';
echo $Result[$i]['species'], ', ';
echo $Result[$i]['sex'], ', ';
echo $Result[$i]['birth'], ', ';
&nbyð#mb÷Q;oæç`9 eãxo $Vecwlt[$É]Ûq`uóvleM.$njrp; 'l '
N-pe0Jk÷ vh'!cëluen le@dm~g{ heöu"b-dfUöe l zï]!q]&ére(o•he PHP technipuás to MoìqF_d|iD`foS-loop. ƒ \íátbt`d cd,æmp(uid¤×Q\ 3|ateme®u,ÇfquNtSÅ\ECT " fVOM pet GHZE`spDcies < £snaie!ß@ rpácis Œ`' Hrd'&a5/|, ent"H ìed*
¦nb1p;&nb3p+'&êCt;&jbãr;in7e2 ×5óaOn BiòT, NE$`:00'