nbp;&nss2&fs`&ssp;&odh8ncs;nfBwp;&~b3x;{
{
echo $Fields[$i][$j][0], ' ';
}
echo "<br>";
for ($n=0; $n<count($Result[$i][$n]); ++$n)
{
if ($Result[$i]['arrayName'] === 'Error')
{
echo 'Error Code => ', $Result[$i]['arrayName'], ' ';
echo 'SQLState => ', $Result[$i]['SQLState'], ' ';
echo 'Error Message => ', $Result[$i]['info'];
echo "<br>";
}
elseif($Result[$i]['arrayName'] === 'OK')
{
echo 'affectedRows => ', $Result[$i]['affectedRows'], ' ';
echo 'last_insert_id => ', $Result[$i]['last_insert_id'], ' ';
echo 'No. of Warnings => ', $Result[$i]['noOfWarnings'];
echo 'OK Message => ', $Result[$i]['info'];
echo "<br>";
}
else
{
for ($k=0; $k<count($Fields[$i]); ++$k)
{
$fieldName = $Fields[$i][$k][0];
echo $Result[$i][$n][$fieldName], ' ';
}
}
echo "<br>";
}
echo "<br>";
}
}
Note that use of the variables $i, $j, $n and the value, zero (0).
In particular, for the fields, each index of the outermost structure corresponds to an array of arrays. Each array of array gives the field properties of a resultset.
I tried the above code and I had:
name owner species sex birth death
Bows Diane dog m 1989-08-31 2005-07-29
name owner species sex birth death
Chirpy Susan bird f 2008-09-11 NULL
Singer Susan bird NULL 2007-12-09 NULL
Fat Benny snake m 2006-04-29 NULL
The structure of an error array/associative is:
[
{
bodyLength => $bodyLenD,
seqNo => $seqNo,
errNo => $errNo,
errCode => $error_code_D,
SQLState => $SQLStateStr,
info => $info,
arrayName => 'Error'
}
]
[
{
bodyLength => $bodyLenD;
seqNo => $seqNo;
okNo => $okNo;
affectedRows => $affected_Rows;
last_insert_id => $last_insert_id;
noOfWarnings => $noOfWarnings_D;
info => $info;
arrayName => 'OK';
}
]
For the above two structures, the outermost array (one cell) is not shown.
The structure of a multi-resultset (not a single resultset) array/array/associative is similar to (not an example of this series):
[
[
{ProductID=>1, ProductName=>"TV Set", Category=> "Entertainment", Number=>50, CostPrice=>25, SellingPrice=>30},
{ProductID=>1, ProductName=>"VCD", Category=>"Entertainment", Number=>50, CostPrice=>20, SellingPrice=>25},
{ProductID=>3, ProductName=>"Clothe Box", Category=>"Household", Number=>45, CostPrice=>16, SellingPrice=>21}
]
[
{ProductID=>5, ProductName=>"Banana", Category=>"Fruit", Number=>125, CostPrice=>5, SellingPrice=>7},
{ProductID=>6, ProductName=>"Pear", Category=>"Fruit", Number=>135, CostPrice=>3, SellingPrice=>4}
]
]
The following is a code example of a stored procedure (after selecting the database):
$procedureStr = "CREATE PROCEDURE sampleProced (OUT parA DATE)
BEGIN
SELECT birth
FROM pet
WHERE name = 'Claws'
INTO parA;
END";
if (!query($procedureStr))
{
echo $Error_msg, "<br>";
}
else
{
echo "procedure saved <br>";
}
$setStr = 'SET @val = NULL';
if (!query($setStr))
{
echo $Error_msg, "<br>";
}
else
{
echo "variable set <br>";
}
$procedureCall = "CALL sampleProced(@val)";
if (!query($procedureCall))
{
echo $Error_msg, "<br>";
}
else
{
echo "procedure called <br>";
}
$selStr = "SELECT @val";
if (!query($selStr))
{
echo $Error_msg, "<br>";
}
else
{
for ($j=0; $j<$No_of_Columns; ++$j)
{
echo $Fields[$j][0], ' ';
}
echo "<br>";
for ($i=0; $i<$No_of_Rows; ++$i)
{
for ($j=0; $j<$No_of_Columns; ++$j)
{
$fieldName = $Fields[$j][0];
echo $Result[$i][$fieldName], ', ';
}
echo "<br>";
}
}
I tried the code and I had:
procedure saved
variable set
procedure called
@val
2004-03-17,
That is it for this part of the series. We stop here and continue in the next part.
Chrys
Related Links
Pure PHP Mailsend - sendmailPurePHP MySQL API
Using the PurePHP MySQL API
More Related Links
Basics of PHP with Security Considerations
cousins
Using the EMySQL API
Using the PurePerl MySQL API
BACK NEXT