note 113946 added to class.mysqli-stmt

From: Date: Fri, 20 Dec 2013 11:35:46 +0000
Subject: note 113946 added to class.mysqli-stmt
Groups: php.notes 
Request: Send a blank email to php-notes+get-197988@lists.php.net to get a copy of this message
<?php class MySQL { protected $mysql; function __construct() { //Get MySQL config values from config.ini file if($config = parse_ini_file("../config.ini")) { // Obtener los valores del fichero de configuración config.ini $ip = $config["ip"]; $user = $config["usuario"]; $pass = $config["password"]; $bd = $config["bd"]; //Connection between a database and php $this->mysql = new mysqli($ip, $user, $pass, $bd); } } function setResultQuery($query, $param) { $array = NULL; if(!$this->mysql->connect_errno) { $stmt = $this->setStatement($query, $param); try { if($stmt != NULL) { if($stmt->execute()) { //Obtener resultados $stmt->store_result(); $variables = array(); $data = array(); $meta = $stmt->result_metadata(); while($field = $meta->fetch_field()) { $variables[] = &$data[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $variables); $i=0; while($stmt->fetch()) { $array[$i] = array(); foreach($data as $k=>$v) $array[$i][$k] = $v; $i++; } $stmt->close(); } } }catch(Exception $e){ $array = FALSE; } } return $array; } function setStatement($query, $param) { try { $stmt = $this->mysql->prepare($query); $ref = new ReflectionClass('mysqli_stmt'); if(count($param) != 0) { $method = $ref->getMethod('bind_param'); $method->invokeArgs($stmt, $param); } }catch(Exception $e){ if($stmt != null) { $stmt->close(); } } return $stmt; } function setNoResultQuery($query, $param) { $validation = FALSE; if(!$this->mysql->connect_errno) { try { $stmt = $this->setStatement($query, $param); if($stmt != null) { if($stmt->execute()) { $stmt->close(); $validacion = TRUE; } } }catch(Exception $e){ $validation = FALSE; } } return $validation; } function __destruct() { $this->mysql->close(); } } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/class.mysqli-stmt.php Edit -- https://master.php.net/note/edit/113946 Del: integrated -- https://master.php.net/note/delete/113946/integrated Del: useless -- https://master.php.net/note/delete/113946/useless Del: bad code -- https://master.php.net/note/delete/113946/bad+code Del: spam -- https://master.php.net/note/delete/113946/spam Del: non-english -- https://master.php.net/note/delete/113946/non-english Del: in docs -- https://master.php.net/note/delete/113946/in+docs Del: other reasons-- https://master.php.net/note/delete/113946 Reject -- https://master.php.net/note/reject/113946 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#197988) next »