[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace DebugBar\DataCollector\PDO; 4 5 use PDO; 6 use PDOException; 7 use PDOStatement; 8 9 /** 10 * A traceable PDO statement to use with Traceablepdo 11 */ 12 class TraceablePDOStatement extends PDOStatement 13 { 14 /** @var PDO */ 15 protected $pdo; 16 17 /** @var array */ 18 protected $boundParameters = []; 19 20 /** 21 * TraceablePDOStatement constructor. 22 * 23 * @param TraceablePDO $pdo 24 */ 25 protected function __construct(TraceablePDO $pdo) 26 { 27 $this->pdo = $pdo; 28 } 29 30 /** 31 * Bind a column to a PHP variable 32 * 33 * @link http://php.net/manual/en/pdostatement.bindcolumn.php 34 * @param mixed $column Number of the column (1-indexed) or name of the column in the result set 35 * @param mixed $param Name of the PHP variable to which the column will be bound. 36 * @param int $type [optional] Data type of the parameter, specified by the PDO::PARAM_* 37 * constants. 38 * @param int $maxlen [optional] A hint for pre-allocation. 39 * @param mixed $driverdata [optional] Optional parameter(s) for the driver. 40 * @return bool TRUE on success or FALSE on failure. 41 */ 42 public function bindColumn($column, &$param, $type = null, $maxlen = null, $driverdata = null) 43 { 44 $this->boundParameters[$column] = $param; 45 $args = array_merge([$column, &$param], array_slice(func_get_args(), 2)); 46 return call_user_func_array(['parent', 'bindColumn'], $args); 47 } 48 49 /** 50 * Binds a parameter to the specified variable name 51 * 52 * @link http://php.net/manual/en/pdostatement.bindparam.php 53 * @param mixed $parameter Parameter identifier. For a prepared statement using named 54 * placeholders, this will be a parameter name of the form :name. For a prepared statement using 55 * question mark placeholders, this will be the 1-indexed position of the parameter. 56 * @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter. 57 * @param int $data_type [optional] Explicit data type for the parameter using the PDO::PARAM_* 58 * constants. 59 * @param int $length [optional] Length of the data type. To indicate that a parameter is an OUT 60 * parameter from a stored procedure, you must explicitly set the length. 61 * @param mixed $driver_options [optional] 62 * @return bool TRUE on success or FALSE on failure. 63 */ 64 public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null) 65 { 66 $this->boundParameters[$parameter] = $variable; 67 $args = array_merge([$parameter, &$variable], array_slice(func_get_args(), 2)); 68 return call_user_func_array(['parent', 'bindParam'], $args); 69 } 70 71 /** 72 * Binds a value to a parameter 73 * 74 * @link http://php.net/manual/en/pdostatement.bindvalue.php 75 * @param mixed $parameter Parameter identifier. For a prepared statement using named 76 * placeholders, this will be a parameter name of the form :name. For a prepared statement using 77 * question mark placeholders, this will be the 1-indexed position of the parameter. 78 * @param mixed $value The value to bind to the parameter. 79 * @param int $data_type [optional] Explicit data type for the parameter using the PDO::PARAM_* 80 * constants. 81 * @return bool TRUE on success or FALSE on failure. 82 */ 83 public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR) 84 { 85 $this->boundParameters[$parameter] = $value; 86 return call_user_func_array(['parent', 'bindValue'], func_get_args()); 87 } 88 89 /** 90 * Executes a prepared statement 91 * 92 * @link http://php.net/manual/en/pdostatement.execute.php 93 * @param array $input_parameters [optional] An array of values with as many elements as there 94 * are bound parameters in the SQL statement being executed. All values are treated as 95 * PDO::PARAM_STR. 96 * @throws PDOException 97 * @return bool TRUE on success or FALSE on failure. 98 */ 99 public function execute($input_parameters = null) 100 { 101 $preparedId = spl_object_hash($this); 102 $boundParameters = $this->boundParameters; 103 if (is_array($input_parameters)) { 104 $boundParameters = array_merge($boundParameters, $input_parameters); 105 } 106 107 $trace = new TracedStatement($this->queryString, $boundParameters, $preparedId); 108 $trace->start(); 109 110 $ex = null; 111 try { 112 $result = parent::execute($input_parameters); 113 } catch (PDOException $e) { 114 $ex = $e; 115 } 116 117 if ($this->pdo->getAttribute(PDO::ATTR_ERRMODE) !== PDO::ERRMODE_EXCEPTION && $result === false) { 118 $error = $this->errorInfo(); 119 $ex = new PDOException($error[2], (int) $error[0]); 120 } 121 122 $trace->end($ex, $this->rowCount()); 123 $this->pdo->addExecutedStatement($trace); 124 125 if ($this->pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_EXCEPTION && $ex !== null) { 126 throw $ex; 127 } 128 return $result; 129 } 130 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |