MySQL Forums
Forum List  »  PHP

A question about store procedures.
Posted by: Anson Ng
Date: December 08, 2014 10:00PM

Since i am a newbie of Store procedures i would like to know how to
print out the result on the webpage via php and mysql

i have created a store procedures in my local server for testing.
The name of it is GetAllProducts(), it will display everything contain in the
produce table when you call it.

I now want to display every row of the table from the store procedures GetAllProducts() on a website via Php, therefore i wrote something like this:

<?php
$servername = "localhost";
$username = "root";
$password = "";

$p1="";
$p2="";

try {
$conn = new PDO("mysql:host=$servername;dbname=test", $username, $password);

if ($result_set = $conn->query("CALL GetAllProducts()"))
{
printf("");
while ($row = $result_set->fetch_object()) {
printf("<tr><td>%s</td><td>%s</td></tr>\n",
$row->No, $row->Name);
}
}

} catch (PDOException $pe) {
die("Error occurred:" . $pe->getMessage());
}
$result_set->close();
$dbh->close();

?>

But it returns an error message only when i ran it:
Fatal error: Call to undefined method PDOStatement::fetch_object() in C:\xampp\htdocs\PhpStudy\storeProcedures.php on line 15

Options: ReplyQuote


Subject
Written By
Posted
A question about store procedures.
December 08, 2014 10:00PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.