note 92283 added to mysqli-stmt.bind-param

From: Date: Fri, 17 Jul 2009 15:14:52 +0000
Subject: note 92283 added to mysqli-stmt.bind-param
Groups: php.notes 
Request: Send a blank email to php-notes+get-158417@lists.php.net to get a copy of this message
This might be helpful for someone. I made a class to manage the parameters Its used like this: $stmt = $mysqli->prepare("CALL item_add(?, ?, ?, ?)"); $sp = new Statement_Parameter(); $sp->Add_Parameter('mydescription', Statement_Parameter_Type::$STATEMENT_TYPE_STRING); $sp->Add_Parameter('myean', Statement_Parameter_Type::$STATEMENT_TYPE_STRING); $sp->Add_Parameter('myprice', Statement_Parameter_Type::$STATEMENT_TYPE_DOUBLE); $sp->Add_Parameter('myactive', Statement_Parameter_Type::$STATEMENT_TYPE_INTEGER); // call this to bind the parameters $sp->Bind_Params($stmt); //you can then modify the values as you wish $sp->Set_Parameter('myactive',0); $sp->Set_Parameter('mydescription','whatever'); /* execute prepared statement */ $stmt->execute(); class Statement_Parameter { private $_array = array(); public function __constructor() { } public function Add_Parameter($name, $type, $value = NULL) { $this->_array[$name] = array("type" => $type, "value" => $value); } public function Get_Type_String() { $types = ""; foreach($this->_array as $name => $la) $types .= $la['type']; return $types; } public function Set_Parameter($name, $value) { if (isset($this->_array[$name])) { $this->_array[$name]["value"] = $value; return true; } return false; } public function Bind_Params(&$stmt) { $ar = Array(); $ar[] = $this->Get_Type_String(); foreach($this->_array as $name => $la) $ar[] = &$this->_array[$name]['value']; return call_user_func_array(array($stmt, 'bind_param'),$ar); } } class Statement_Parameter_Type { public static $STATEMENT_TYPE_INTEGER = 'i'; public static $STATEMENT_TYPE_DOUBLE = 'd'; public static $STATEMENT_TYPE_STRING = 's'; public static $STATEMENT_TYPE_BLOB = 'b'; } ---- Server IP: 201.216.232.3 Probable Submitter: 200.69.222.229 ---- Manual Page -- http://www.php.net/manual/en/mysqli-stmt.bind-param.php Edit -- https://master.php.net/note/edit/92283 Del: integrated -- https://master.php.net/note/delete/92283/integrated Del: useless -- https://master.php.net/note/delete/92283/useless Del: bad code -- https://master.php.net/note/delete/92283/bad+code Del: spam -- https://master.php.net/note/delete/92283/spam Del: non-english -- https://master.php.net/note/delete/92283/non-english Del: in docs -- https://master.php.net/note/delete/92283/in+docs Del: other reasons-- https://master.php.net/note/delete/92283 Reject -- https://master.php.net/note/reject/92283 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158417) next »