note 69592 deleted from ref.pdo-mysql by cmb
| From: | cmb@php.net | Date: | Sun, 05 May 2019 15:31:55 +0000 |
| Subject: | note 69592 deleted from ref.pdo-mysql by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210977@lists.php.net to get a copy of this message | ||
Note Submitter: dibakar at talash dot net
----
PDO is much better option for calling procedures, views or triggers of mysql 5.x versions from PHP
instead of using mysqli extension. Following is a simple demo script which can help anybody on how
to call and use mysql procedures through php
try {
$dbh = new PDO('mysql:host=xxx;port=xxx;dbname=xxx', 'xxx', 'xxx',
array( PDO::ATTR_PERSISTENT => false));
$stmt = $dbh->prepare("CALL getname()");
// call the stored procedure
$stmt->execute();
echo "<B>outputting...</B><BR>";
while ($rs = $stmt->fetch(PDO::FETCH_OBJ)) {
echo "output: ".$rs->name."<BR>";
}
echo "<BR><B>".date("r")."</B>";
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}