note 84514 added to mysqli-stmt.bind-param
| From: | jette at nerdgirl dot dk | Date: | Thu, 17 Jul 2008 08:46:37 +0000 |
| Subject: | note 84514 added to mysqli-stmt.bind-param | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141607@lists.php.net to get a copy of this message | ||
I already have a database class that makes everything nice and easy. But when it came to preparing,
binding and executing, I found it was a real challenge to boil things down.
But luckily I stumbled over a bug-report with a workaround, that pointed me in the right direction.:
http://bugs.php.net/bug.php?id=43568
I now execute stored procedures (aka routines) like this:
<?php
$db = new myDb();
$db->execProcedure('call
someProc(?,?)','ss',array('param1','param2'));
?>
And this is the code to make it happen:
(I extracted this example from a bigger context, but you probably get the idea)
<?php
class myDb extends mysqli {
public function __construct() {
//Connection established here
}
public function execProcedure($call,$types,$params) {
$stmt = $this->prepare($call);
$bind_names[] = $types;
for ($i=0; $i<count($params);$i++) {
$bind_name = 'bind' . $i;
$$bind_name = $params[$i];
$bind_names[] = &$$bind_name;
}
$return = call_user_func_array(array($stmt,'bind_param'),$bind_names);
$stmt->execute();
$stmt->close();
}
}
----
Server IP: 195.184.96.15
Probable Submitter: 80.167.105.190
----
Manual Page -- http://www.php.net/manual/en/mysqli-stmt.bind-param.php
Edit -- https://master.php.net/note/edit/84514
Del: integrated -- https://master.php.net/note/delete/84514/integrated
Del: useless -- https://master.php.net/note/delete/84514/useless
Del: bad code -- https://master.php.net/note/delete/84514/bad+code
Del: spam -- https://master.php.net/note/delete/84514/spam
Del: non-english -- https://master.php.net/note/delete/84514/non-english
Del: in docs -- https://master.php.net/note/delete/84514/in+docs
Del: other reasons-- https://master.php.net/note/delete/84514
Reject -- https://master.php.net/note/reject/84514
Search -- https://master.php.net/manage/user-notes.php