I have a PHP page which is passed 3 values from another. These are then passed into a call to a stored procedure.
The SP has an output value too of @e, it's basically a count check to see if the email address passed already exists.
$inUname = $_POST['txtUser'];
$inPword = $_POST['txtPword'];
$inEmail = $_POST['txtEmail'];
$retval = NULL;
$pdo = new PDO("mysql:dbname=$database_fw07d;host=$hostname_fw07d", $username_fw07d, $password_fw07d);
$stmt = $pdo->prepare("CALL sp_createUser(:inUname, :inPword, :inEmail, @e)");
$stmt->bindParam(':inUname', $inUname, PDO::PARAM_STR, 40);
$stmt->bindParam(':inPword', $inPword, PDO::PARAM_STR, 100);
$stmt->bindParam(':inEmail', $inEmail, PDO::PARAM_STR, 80);
$stmt->execute();
$retval = $pdo->query('SELECT @e');
Now this value is coming back as an array and I would have expected to be able to access that value, to pass back to the main page like this,
$result = $retval[0];
print $result;
But this returns nothing.
I then found that using
do {
$results[]= $retval->fetchAll();
} while ($retval->nextRowset());
print_r($results);
gives the values
Array ( [0] => Array ( [0] => Array ( [@e] => 1 [0] => 1 ) ) )
suggesting some form of array tree?
I used
foreach($results as $res => $value){
$$res = $value;
}
print $value;
foreach($value as $val1 => $value1){
$$val1 = $value1;
}
print $value1;
foreach($value1 as $val2 => $value2){
$$val2 = $value2;
}
print $value2;
Which eventually set $value2 to the returned number.
My questions are, is this expected behaviour?
Have I made an error in my execution of this SP?
Is there a way to improve on what I have written so far?