note 97609 added to mysqli-stmt.bind-param

From: Date: Wed, 28 Apr 2010 05:29:53 +0000
Subject: note 97609 added to mysqli-stmt.bind-param
Groups: php.notes 
Request: Send a blank email to php-notes+get-168743@lists.php.net to get a copy of this message
Used the hints above - esp the call_user_func_array - what works simply is passing by reference... <? class MySQL { // so vars that are global to the class var $connection; var $dbc; function __construct () { $this->connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (mysqli_connect_errno()) { //printf("Could not connect to the DB: %s\n", mysqli_connect_error()); // TMI printf("Could not connect to the DB"); exit(); } } function DBi($info) { // a call has this array structure // $this->info['params'] = array('is', &$user, &$name); // $this->info['query'] = "select id, username, role_id from users where id = ? and name = ?"; // $this->info['close'] = "false"; // return $stmt for further work // $mysqli = $this->connection; $params = $info['params']; // print_r($info); // debug if ($stmt = $mysqli->prepare($info['query'])) { $ret = call_user_func_array (array($stmt,'bind_param'),$info['params']); // $ret not used yet... $stmt->execute(); if ($info['close'] == "true") { $result = $mysqli->affected_rows; $stmt->close(); return $result; } else { return $stmt; } } else { printf("Prepared Statement Error: $server_id \n"); } } } ?> The close is generally for inserts, else the $stmt is returned for further processing... <? // call the method to run the prepared query, then return statement handle. If just wanted an insert, use close = true if ( is_int($user) ) { $this->info['params'] = array('is', &$user, &$name); $this->info['query'] = "select id, username, role_id from users where id = ? and name = ?"; $this->info['close'] = "false"; // return $stmt for further work $stmt = parent::DBi($this->info); $stmt->bind_result($col1, $col2, $col3); while( $stmt->fetch() ) { $res['id'] = $col1; $res['username'] = $col2; $res['role_id'] = $col3; $res['error'] = 0; } $stmt->close; return $res; } ?> ---- Server IP: 128.39.198.38 Probable Submitter: 99.2.150.42 ---- Manual Page -- http://www.php.net/manual/en/mysqli-stmt.bind-param.php Edit -- https://master.php.net/note/edit/97609 Del: integrated -- https://master.php.net/note/delete/97609/integrated Del: useless -- https://master.php.net/note/delete/97609/useless Del: bad code -- https://master.php.net/note/delete/97609/bad+code Del: spam -- https://master.php.net/note/delete/97609/spam Del: non-english -- https://master.php.net/note/delete/97609/non-english Del: in docs -- https://master.php.net/note/delete/97609/in+docs Del: other reasons-- https://master.php.net/note/delete/97609 Reject -- https://master.php.net/note/reject/97609 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168743) next »