note 101952 added to mysqli-stmt.bind-param
| From: | renatoly at gmail dot com | Date: | Wed, 19 Jan 2011 22:55:06 +0000 |
| Subject: | note 101952 added to mysqli-stmt.bind-param | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175915@lists.php.net to get a copy of this message | ||
Based on the function wrote by canche_x at yahoo dot com, I wrote this new function that is a bit
more clear. Specially when executing select, show vs insert, updates & deletes:
Example of how to use it:
$statement = "Select 1 as result from userscashier where idcashier=? and idsala=? and
username=? and password=? and ip=?";
$resultset = $dbhandler::preparedQuery($statement,
array('iisss',$pidCashier,$pidSala,$puserName,$ppassword,$pip), TRUE);
echo '<br \>the number of records found: ' . $resultset;
if ($resultset) {
$statement = "Select nextval('idAuthSN') as idAuthSN";
$resultset = $dbhandler::preparedQuery($statement,array(), TRUE, $rs);
echo '<br \> Pepe pepe pepe The idauthsn is ' . $rs[0]['idAuthSN'];
$this->setAuthSN($rs[0]['idAuthSN']);
$this->setAuthSignature(sha1($rs[0]['idAuthSN'] . CsUtilities::SECKEY));
//echo 'the secret code is ' . CsUtilities::SECKEY;
$statement = "Insert into authenticatedcashiers values (?,?)";
$resultset = $dbhandler::preparedQuery($statement,array('ss',$this->getAuthSN(),
$this->getAuthSignature()), FALSE);
echo "<br \> Number of inserted rows $resultset <br \>";
return true;
}
public static function preparedQuery ($statement, $params, $select=TRUE, &$rs=NULL) {
$mysqli = self::getConnection();
if ($stmt = $mysqli->prepare($statement)) {
if (count($params)>0)
call_user_func_array(array($stmt, 'bind_param'), self::refValues($params));
$stmt->execute();
if(!$select) {
$result = $mysqli->affected_rows;
}
else {
$meta = $stmt->result_metadata();
if ($meta) {
while ( $field = $meta->fetch_field() ) {
$parameters[] = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), self::refValues($parameters));
while ( $stmt->fetch() ) {
$x = array();
foreach( $row as $key => $val ) {
$x[$key] = $val;
}
$results[] = $x;
}
$rs = $results;
$result = count($results);
}
else
$result = 0;
}
$stmt->close();
return $result;
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 190.129.66.55
----
Manual Page -- http://www.php.net/manual/en/mysqli-stmt.bind-param.php
Edit -- https://master.php.net/note/edit/101952
Del: integrated -- https://master.php.net/note/delete/101952/integrated
Del: useless -- https://master.php.net/note/delete/101952/useless
Del: bad code -- https://master.php.net/note/delete/101952/bad+code
Del: spam -- https://master.php.net/note/delete/101952/spam
Del: non-english -- https://master.php.net/note/delete/101952/non-english
Del: in docs -- https://master.php.net/note/delete/101952/in+docs
Del: other reasons-- https://master.php.net/note/delete/101952
Reject -- https://master.php.net/note/reject/101952
Search -- https://master.php.net/manage/user-notes.php