public function bind(PDOStatement $stmt, $value) { $param = $value[0]; $param->__init__(); $propertyNames = $param->getPropertyNames(); foreach ($this->bindKeys as $index => $key) { $bindKey = ':' . $key; if ($this->info->typeofIn($key)) { if (!in_array($key, $propertyNames)) { throw new InvalidArgumentException('param ' . $param . ' has not propery: ' . $key . ' instatement: ' . $stmt->queryString); } $stmt->bindParam($bindKey, $param->get($key)); continue; } $paramValue = null; if ($param->issetValue($key)) { $paramValue = $param->get($key); } if (null === $paramValue) { $stmt->bindParam($bindKey, $paramValue, PDO::PARAM_NULL | PDO::PARAM_INPUT_OUTPUT); continue; } $gettype = gettype($paramValue); $paramType = -1; if (isset(self::$pdoTypes[$gettype])) { $paramType = self::$pdoTypes[$gettype] | PDO::PARAM_INPUT_OUTPUT; } else { $paramType = PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT; } $stmt->bindParam($bindKey, $paramValue, $paramType); } }
public function bindParam($parameter, $variable, $data_type = PDO::PARAM_STR, $length = 0) { if ($length) { $this->statement->bindParam($parameter, $variable, $data_type, $length); } else { $this->statement->bindParam($parameter, $variable, $data_type); } }
/** * Bind a value of the param SQL * @access public * @param string $column * @param mixed $param * @param string $type * @return void */ public function bindParam($column, &$param, $type = null) { if ($type === null) { $this->_statement->bindParam($column, $param); } else { $this->_statement->bindParam($column, $param, $type); } }
/** * Bind parameters from container * * @param ParameterContainer $container */ protected function bindParametersFromContainer(ParameterContainer $container) { $parameters = $container->getNamedArray(); foreach ($parameters as $position => &$value) { $type = \PDO::PARAM_STR; if ($container->offsetHasErrata($position)) { switch ($container->offsetGetErrata($position)) { case ParameterContainer::TYPE_INTEGER: $type = \PDO::PARAM_INT; break; case ParameterContainer::TYPE_NULL: $type = \PDO::PARAM_NULL; break; case ParameterContainer::TYPE_LOB: $type = \PDO::PARAM_LOB; break; case is_bool($value): $type = \PDO::PARAM_BOOL; break; } } // parameter is named or positional, value is reference $parameter = is_int($position) ? $position + 1 : $position; $this->resource->bindParam($parameter, $value, $type); } }
/** * Bind parameters from container */ protected function bindParametersFromContainer() { if ($this->parametersBound) { return; } $parameters = $this->parameterContainer->getNamedArray(); foreach ($parameters as $name => &$value) { if (is_bool($value)) { $type = \PDO::PARAM_BOOL; } else { $type = \PDO::PARAM_STR; } if ($this->parameterContainer->offsetHasErrata($name)) { switch ($this->parameterContainer->offsetGetErrata($name)) { case ParameterContainer::TYPE_INTEGER: $type = \PDO::PARAM_INT; break; case ParameterContainer::TYPE_NULL: $type = \PDO::PARAM_NULL; break; case ParameterContainer::TYPE_LOB: $type = \PDO::PARAM_LOB; break; } } // parameter is named or positional, value is reference $parameter = is_int($name) ? $name + 1 : $name; $this->resource->bindParam($parameter, $value, $type); } }
protected function Execute($Sql) { $this->Stmt = $this->prepare($Sql, $this->InfoConexaoBD); //procura falsos atá não encontrar mais if (!empty($this->Dados)) { foreach ($this->Dados as $value) { if (in_array('false', $this->Dados)) { $this->isFalse(); } else { break; } } } if ($this->Dados && array_key_exists('limit', $this->Dados)) { $Limit = (int) $this->Dados['limit']; $this->Stmt->bindParam(':limit', $Limit, PDO::PARAM_INT); unset($this->Dados['limit']); } if ($this->Dados && array_key_exists('offset', $this->Dados)) { $Offset = (int) $this->Dados['offset']; $this->Stmt->bindParam(':offset', $Offset, PDO::PARAM_INT); unset($this->Dados['offset']); } if ($this->BindParam) { foreach ($this->Dados as $dado => $value) { $this->Stmt->bindParam(":{$dado}", $value); } $this->Dados = null; } }
/** * Executes the generated query. * @return boolean Was query successfull or not. */ public function execute() { $this->queryStr = $this->buildQuery(); // Connect and execute $this->connect(); if ($this->prepared && $this->tokenCount > 0) { // Prepare tokenised values. $this->sth = $this->dbh->prepare($this->queryStr); foreach ($this->tokens as $token) { $this->sth->bindParam($token['token'], $token['value']); } if (!$this->sth->execute()) { $this->reset(); return false; } } else { foreach ($this->tokens as $token) { $this->queryStr = str_replace($token['token'], $this->dbh->quote($token['value']), $this->queryStr); } $this->sth = $this->dbh->query($this->queryStr); if ($this->sth === false) { $this->reset(); return false; } $this->dbh->errorInfo(); } $this->lastQuery = $this->queryStr; $this->reset(); return true; }
/** * Binds a variable to a parameter, the value will be evaluated at execution time * * @param mixed $parameter * @param mixed $variable * @param int $dataType * @param null $length * @param null $driverOptions * * @return bool */ public function bindParam($parameter, &$variable, $dataType = PDO::PARAM_STR, $length = null, $driverOptions = null) { if ($this->trackDataType($dataType)) { $this->params[$dataType][$this->parameter($parameter)] =& $variable; } return parent::bindParam($parameter, $variable, $dataType, $length, $driverOptions); }
/** * {@inheritdoc} */ public function bindParam($column, &$variable, $type = \PDO::PARAM_STR, $length = null, $driverOptions = null) { try { return parent::bindParam($column, $variable, $type, $length, $driverOptions); } catch (\PDOException $exception) { throw new PDOException($exception); } }
public function executeStatement() { $this->currentQuery = $this->pdo->prepare($this->currentStatement); foreach ($this->currentParams as $param => $info) { $this->currentQuery->bindParam($param, $info['value'], $info['type']); } $initTime = microtime(); $result = $this->currentQuery->execute(); $endTime = microtime(); if (Profiler::getState()) { /** @var PDORepositoryProfiler $profiler */ $profiler = PDORepositoryProfiler::getInstance(); $execTime = $this->calcQueryExecutionDuration($initTime, $endTime); $profiler->addTrace($this->currentStatement, $this->currentParams, $result, $this->getErrorInfo(), $execTime); } return $result; }
/** * Binds a parameter to the specified variable name. * * @param mixed $parameter Name the parameter, either integer or string. * @param mixed $variable Reference to PHP variable containing the value. * @param mixed $type OPTIONAL Datatype of SQL parameter. * @param mixed $length OPTIONAL Length of SQL parameter. * @param mixed $options OPTIONAL Other options. * @return bool * @throws Zend_Db_Statement_Exception */ protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null) { try { return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options); } catch (PDOException $e) { require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage()); } }
public function bindParam($parameter, &$variable, $data_type = \PDO::PARAM_STR, $length = 0, $driver_options = array()) { if (\PDO::PARAM_STR == $data_type) { $this->params[$parameter] = "'" . $variable . "'"; } else { $this->params[$parameter] = $variable; } parent::bindParam($parameter, $variable, $data_type, $length, $driver_options); }
/** * Permet d'exécuter une requête. * * Aucun résultat n'est renvoyé par cette fonction. Elle doit être utilisé pour effectuer * des insertions, des updates... Elle est de même utilisée par les * autres fonction de la classe comme queryRow() et queryTab(). * * @param string $query chaine SQL * @param mixed $param variables bind de type array(":bind"=>"value") * @return void */ public function query($query, $param = array()) { global $sysNbQuery; // execution de la requête $this->query = (isset($_SERVER['HOSTNAME']) ? '/*SIG'.$_SERVER['HOSTNAME'].'SIG*/ ' : '').$query; $this->param = $param; $this->errorParams = array(); $this->errorParams['Request'] = $query; $this->errorParams['Bind'] = $param; $this->id->setAttribute(PDO::ATTR_AUTOCOMMIT, $this->getCommitMode()); $this->id->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $sysNbQuery = (!isset($sysNbQuery) || $sysNbQuery<=0) ? 1 : $sysNbQuery+1; // Prepare de la requête $queryMD5 = md5($query); if(!isset($this->aPrepare[$queryMD5])) { $this->lPrepare = $this->id->prepare($this->query); $this->aPrepare[$queryMD5] = $this->lPrepare; } else { $this->lPrepare = $this->aPrepare[$queryMD5]; } if ($this->lPrepare!==false) { // Bind des paramètres if($param) { foreach($param as $key => $val) { if (strpos($query, $key) !== false) { if($param[$key]===null) $this->lPrepare->bindParam(trim($key), $param[$key], PDO::PARAM_NULL); else $this->lPrepare->bindParam(trim($key), $param[$key]); } } } // Execution de la requête $rs = $this->lPrepare->execute(); if ($this->lPrepare->errorCode() != PDO::ERR_NONE) { $this->errorParams['errorInfo'] = $this->lPrepare->errorInfo(); //echo'<xmp>Erreur execute() de PDO : '.$this->errorParams['errorInfo'][2];print_r($query);echo'</xmp>'; //Génération d'une DataBaseException //throw new DataBaseException("Erreur execute() de PDO",$error[2],$this->errorParams); } return $rs; }else{ $this->errorParams['errorInfo'] = $this->lPrepare->errorInfo(); //echo'<xmp>Erreur prepare() de PDO : '.$this->errorParams['errorInfo'][2];print_r($query);echo'</xmp>'; //DatabaseManager::log($this, true); //throw new DataBaseException("Erreur prepare() de PDO",$this->id->errorInfo(),$this->errorParams); } return false; }
/** * Bind values to PDO statement. * * @param array $values * @param \PDOStatement $statement * @param int $parameter * @return int */ private function bindValues(&$values, $statement, $parameter) { $count = count($values); for ($i = 0; $i < $count; $i++) { $type = $this->getPdoType($values[$i]); $statement->bindParam($parameter, $values[$i], $type); $parameter++; } return $parameter; }
/** * @param PDOStatement $result * @param array $data */ private function bind($result, $data) { foreach ($data as $i => &$row) { if (is_array($row)) { $c = count($row); if ($c == 2) { $result->bindParam($row[0], $row[1]); } elseif ($c == 3) { $result->bindParam($row[0], $row[1], $row[2]); } elseif ($c == 4) { $result->bindParam($row[0], $row[1], $row[2], $row[3]); } elseif ($c == 5) { $result->bindParam($row[0], $row[1], $row[2], $row[3], $row[4]); } } else { $result->bindParam($i, $row); } } }
/** * @param Buffer $blockHash * @return TransactionCollection */ public function fetchBlockTransactions(Buffer $blockHash) { if ($this->debug) { echo sprintf('[db] called fetchBlockTransactions (%s)', $blockHash->getHex()); } if (null === $this->txsStmt) { $this->txsStmt = $this->dbh->prepare(' SELECT t.hash, t.version, t.nLockTime FROM transactions t JOIN block_transactions bt ON bt.transaction_hash = t.hash WHERE bt.block_hash = :hash '); $this->txInStmt = $this->dbh->prepare(' SELECT txIn.parent_tx, txIn.hashPrevOut, txIn.nPrevOut, txIn.scriptSig, txIn.nSequence FROM transaction_input txIn JOIN block_transactions bt ON bt.transaction_hash = txIn.parent_tx WHERE bt.block_hash = :hash GROUP BY txIn.parent_tx ORDER BY txIn.nInput '); $this->txOutStmt = $this->dbh->prepare(' SELECT txOut.parent_tx, txOut.value, txOut.scriptPubKey FROM transaction_output txOut JOIN block_transactions bt ON bt.transaction_hash = txOut.parent_tx WHERE bt.block_hash = :hash GROUP BY txOut.parent_tx ORDER BY txOut.nOutput '); } $hexHash = $blockHash->getHex(); // We pass a callback instead of looping $this->txsStmt->bindValue(':hash', $hexHash); $this->txsStmt->execute(); /** @var TxBuilder[] $builder */ $builder = []; $this->txsStmt->fetchAll(\PDO::FETCH_FUNC, function ($hash, $version, $locktime) use(&$builder) { $builder[$hash] = (new TxBuilder())->version($version)->locktime($locktime); }); $this->txInStmt->bindParam(':hash', $hexHash); $this->txInStmt->execute(); $this->txInStmt->fetchAll(\PDO::FETCH_FUNC, function ($parent_tx, $hashPrevOut, $nPrevOut, $scriptSig, $nSequence) use(&$builder) { $builder[$parent_tx]->input($hashPrevOut, $nPrevOut, new Script(new Buffer($scriptSig)), $nSequence); }); $this->txOutStmt->bindParam(':hash', $hexHash); $this->txOutStmt->execute(); $this->txOutStmt->fetchAll(\PDO::FETCH_FUNC, function ($parent_tx, $value, $scriptPubKey) use(&$builder) { $builder[$parent_tx]->output($value, new Script(new Buffer($scriptPubKey))); }); $txs = []; foreach ($builder as $txBuilder) { $txs[] = $txBuilder->get(); } unset($builder); return new TransactionCollection($txs); }
/** * Permet d'exécuter une requête. * * Aucun résultat n'est renvoyé par cette fonction. Elle doit être utilisé pour effectuer * des insertions, des updates... Elle est de même utilisée par les * autres fonction de la classe comme queryRow() et queryTab(). * * @param string $query chaine SQL * @param mixed $param variables bind de type array(":bind"=>"value") * @return void */ public function query($query, $param = array()) { global $sysNbQuery; // execution de la requête $this->query = (isset($_SERVER['HOSTNAME']) ? '/*SIG' . $_SERVER['HOSTNAME'] . 'SIG*/ ' : '') . $query; $this->param = $param; $this->stmt = null; $this->id->setAttribute(PDO::ATTR_AUTOCOMMIT, $this->getCommitMode()); $this->id->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $sysNbQuery = (!isset($sysNbQuery) || $sysNbQuery <= 0) ? 1 : $sysNbQuery + 1; try { // Prepare de la requête $this->stmt = $this->id->prepare($this->query); if ($this->stmt !== false) { // Bind des paramètres if (!empty($param)) { foreach ($param as $key => $val) { // ATTENTION, il faut $param[$key] et pas $val car c'est un passage par référence // les valeurs seront évaluées à l'exécution du statement if (strpos($query, $key) !== false) { if ($param[$key] === null) { $this->stmt->bindParam(trim($key), $param[$key], PDO::PARAM_NULL); } else { $this->stmt->bindParam(trim($key), $param[$key]); } } // sinon rien, clés en trop autorisées } } // Execution de la requête $this->data = $this->stmt->execute(); if ($this->stmt->errorCode() != PDO::ERR_NONE) { //Génération d'une DataBaseException $error = $this->stmt->errorInfo(); throw new DataBaseException($error[2], $error[0]); } return $this->data; } else { //Génération d'une DataBaseException $error = $this->stmt->errorInfo(); throw new DataBaseException($error[2], $error[0]); } } catch (PDOException $e) { // Transformation de PDOException en DataBaseException throw new DataBaseException($e->getMessage(), $e->getCode()); } }
/** * Binds a parameter to the specified variable name. * * @param mixed $parameter Name the parameter, either integer or string. * @param mixed $variable Reference to PHP variable containing the value. * @param mixed $type OPTIONAL Datatype of SQL parameter. * @param mixed $length OPTIONAL Length of SQL parameter. * @param mixed $options OPTIONAL Other options. * @return bool * @throws Zend_Db_Statement_Exception */ public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null) { if (is_string($parameter) && $parameter[0] != ':') { $parameter = ":{$parameter}"; } try { return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options); } catch (PDOException $e) { require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage()); } }
private function saveOrUpdateCotations(PDOStatement $query, Cotation $cotation) { //$query = $this->session->prepare($sql); $query->bindParam(":code", $cotation->getCode()); $query->bindParam(":open", str_replace(",", "", $cotation->getOpen())); $query->bindParam(":close", str_replace(",", "", $cotation->getClose())); $query->bindParam(":max", str_replace(",", "", $cotation->getMax())); $query->bindParam(":min", str_replace(",", "", $cotation->getMin())); $query->bindParam(":diff", str_replace(",", "", $cotation->getDiff())); $query->bindParam(":openCont", str_replace(",", "", $cotation->openContracts())); $query->bindParam(":date", date('Y-m-d')); $query->execute(); return $query->rowCount(); }
/** * Permet d'exécuter une requête. * * Aucun résultat n'est renvoyé par cette fonction. Elle doit être utilisé pour effectuer * des insertions, des updates... Elle est de même utilisée par les * autres fonction de la classe comme queryRow() et queryTab(). * * @param string $query chaine SQL * @param mixed $param variables bind de type array(":bind"=>"value") * @return void */ public function query($query, $param = array()) { global $sysNbQuery; // execution de la requête $this->query = (isset($_SERVER['HOSTNAME']) ? '/*SIG'.$_SERVER['HOSTNAME'].'SIG*/ ' : '').$query; $this->param = $param; $this->stmt = null; $this->id->setAttribute(PDO::ATTR_AUTOCOMMIT, $this->getCommitMode()); $this->id->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $sysNbQuery = (!isset($sysNbQuery) || $sysNbQuery<=0) ? 1 : $sysNbQuery+1; try{ // Prepare de la requête $this->stmt = $this->id->prepare($this->query); if ($this->stmt!==false) { // Bind des paramètres if(!empty($param)) { foreach($param as $key => $val) { if (strpos($query, $key) !== false) { if($param[$key]===null) $this->stmt->bindParam(trim($key), $param[$key], PDO::PARAM_NULL); else $this->stmt->bindParam(trim($key), $param[$key]); } } } // Execution de la requête $this->data = $this->stmt->execute(); if ($this->stmt->errorCode() != PDO::ERR_NONE) { //Génération d'une DataBaseException $error = $this->stmt->errorInfo(); throw new DataBaseException($error[2], $error[0]); } return $this->data; }else{ //Génération d'une DataBaseException $error = $this->stmt->errorInfo(); throw new DataBaseException($error[2], $error[0]); } } catch(PDOException $e) { //Génération d'une DataBaseException throw new DataBaseException($e->getMessage(), $e->getCode()); } }
/** * {@inheritdoc} * * @throws \Orno\Db\Exception\BindingException * @throws \Orno\Db\Exception\NoResourceException * @param mixed $placeholder * @param mixed $value * @param integer $type * @param integer $maxlen * @return \Orno\Db\Driver\Pdo */ public function bind($placeholder, $value, $type = self::PARAM_STR, $maxlen = 0) { if (!$this->statement instanceof \PDOStatement) { throw new Exception\NoResourceException(sprintf('%s expects a query to have been prepared', __METHOD__)); } $type = $this->getValueType($type); if ($maxlen > 0) { $this->statement->bindParam($placeholder, $value, $type, (int) $maxlen); } else { $this->statement->bindParam($placeholder, $value, $type); } return $this; }
/** * Bind values to PDO statement. * * @param array $values * @param \PDOStatement $statement * @param int $parameter * @return int */ private function bindValues(&$values, $statement, $parameter) { $count = count($values); for ($i = 0; $i < $count; $i++) { if ($values[$i] instanceof \DateTime) { $values[$i] = (string) $values[$i]; } $type = $this->getPdoType($values[$i]); $statement->bindParam($parameter, $values[$i], $type); $parameter++; } return $parameter; }
/** * Binds parameters. This method binds parameters to a\PDOStatement for * Query Execution. This method binds parameters as NULL, INTEGER or STRING * and supports both named keys and question mark keys. * * @param \PDOStatement $statement \PDO Statement instance * @param array $bindings values that need to get bound to the statement * * @return void */ protected function bindParams($statement, $bindings) { foreach ($bindings as $key => &$value) { if (is_integer($key)) { if (is_null($value)) { $statement->bindValue($key + 1, NULL, \PDO::PARAM_NULL); } elseif (!$this->flagUseStringOnlyBinding && AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) { $statement->bindParam($key + 1, $value, \PDO::PARAM_INT); } else { $statement->bindParam($key + 1, $value, \PDO::PARAM_STR); } } else { if (is_null($value)) { $statement->bindValue($key, NULL, \PDO::PARAM_NULL); } elseif (!$this->flagUseStringOnlyBinding && AQueryWriter::canBeTreatedAsInt($value) && $value < 2147483648) { $statement->bindParam($key, $value, \PDO::PARAM_INT); } else { $statement->bindParam($key, $value, \PDO::PARAM_STR); } } } }
/** * @covers Fabfuel\Prophiler\Decorator\PDO\PDOStatement::execute * @covers Fabfuel\Prophiler\Decorator\PDO\PDOStatement::bindParam * @uses Fabfuel\Prophiler\Decorator\PDO\PDOStatement */ public function testExecute() { $lorem = 'ipsum'; $inputParameters = ['foo' => 'bar']; $boundParameters = ['lorem' => $lorem]; $metadata = ['input parameters' => $inputParameters, 'bound parameters' => $boundParameters, 'query' => null]; $benchmark = $this->getMock('Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface'); $this->profiler->expects($this->once())->method('start')->with('PDOStatement::execute', $metadata, 'Database')->willReturn($benchmark); $this->profiler->expects($this->once())->method('stop')->with($benchmark); $this->pdoStatement->expects($this->once())->method('execute')->with($inputParameters)->willReturn(true); $this->decorator->bindParam('lorem', $lorem); $result = $this->decorator->execute($inputParameters); $this->assertTrue($result); }
/** * Binds a parameter to the SQL statement to be executed. * @param mixed $name Parameter identifier. For a prepared statement * using named placeholders, this will be a parameter name of * the form :name. For a prepared statement using question mark * placeholders, this will be the 1-indexed position of the parameter. * @param mixed $value Name of the PHP variable to bind to the SQL statement parameter * @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value. * @param integer $length length of the data type * @param mixed $driverOptions the driver-specific options (this is available since version 1.1.6) * @return \Database\Command the current command being executed * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php */ public function bindParam($name, &$value, $dataType = null, $length = null, $driverOptions = null) { $this->prepare(); if ($dataType === null) { $this->_statement->bindParam($name, $value, $this->_connection->getPdoType(gettype($value))); } elseif ($length === null) { $this->_statement->bindParam($name, $value, $dataType); } elseif ($driverOptions === null) { $this->_statement->bindParam($name, $value, $dataType, $length); } else { $this->_statement->bindParam($name, $value, $dataType, $length, $driverOptions); } $this->_paramLog[$name] =& $value; return $this; }
/** * @see DBAdapter::bindValue() */ public function bindValue(PDOStatement $stmt, $parameter, $value, ColumnMap $cMap) { if ($cMap->isTemporal()) { $value = $this->formatTemporalValue($value, $cMap); } elseif (is_resource($value) && $cMap->isLob()) { // we always need to make sure that the stream is rewound, otherwise nothing will // get written to database. rewind($value); // pdo_sqlsrv must have bind binaries using bindParam so that the PDO::SQLSRV_ENCODING_BINARY // driver option can be utilized. This requires a unique blob parameter because the bindParam // value is passed by reference and if we didn't do this then the referenced parameter value // would change on the next loop $blob = "blob" . $position; ${$blob} = $value; return $stmt->bindParam($parameter, ${$blob}, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); } return $stmt->bindValue($parameter, $value, $cMap->getPdoType()); }
/** * Bind parameter by param to PDO statement * * @param string $param * Parameter name * @param mixed $value * Parameter value * @param string $type * Optional parameter datatype */ public function bindParam($param, &$value, $type = null) { if (is_null($type)) { switch (true) { case is_int($value): $type = \PDO::PARAM_INT; break; case is_bool($value): $type = \PDO::PARAM_BOOL; break; case is_null($value): $type = \PDO::PARAM_NULL; break; default: $type = \PDO::PARAM_STR; } } $this->stmt->bindParam($param, $value, $type); }
/** * Binds a parameter to the specified variable name. * * Note: This method exists because pass-by-reference won't work with * call_user_func_array(); * * @param mixed $parameter Name the parameter, either integer or string. * @param mixed $variable Reference to PHP variable containing the value. * @param mixed $type OPTIONAL: PDO::PARAM_* Type hint. * @param mixed $length OPTIONAL: Length of SQL parameter. * @param mixed $options OPTIONAL: Other options. * @return bool TRUE on success, FALSE on failure */ public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null) { $parameter = $this->_checkParam($parameter); try { if ($type === null) { if (is_bool($variable)) { $type = PDO::PARAM_BOOL; } elseif (is_null($variable)) { $type = PDO::PARAM_NULL; } elseif (is_integer($variable)) { $type = PDO::PARAM_INT; } else { $type = PDO::PARAM_STR; } } return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options); } catch (PDOException $e) { throw new DBALite_Exception("Error binding parameter", $e); } }
protected function Execute($Sql) { $this->Stmt = Conn::prepare($Sql); if ($this->Dados && array_key_exists('limit', $this->Dados)) { $Limit = (int) $this->Dados['limit']; $this->Stmt->bindParam(':limit', $Limit, PDO::PARAM_INT); unset($this->Dados['limit']); } if ($this->Dados && array_key_exists('offset', $this->Dados)) { $Offset = (int) $this->Dados['offset']; $this->Stmt->bindParam(':offset', $Offset, PDO::PARAM_INT); unset($this->Dados['offset']); } if ($this->BindParam) { foreach ($this->Dados as $dado => $value) { $this->Stmt->bindParam(":{$dado}", $value); } $this->Dados = null; } }
/** * Binds a parameter to the specified variable name. * * @param mixed $parameter Name the parameter, either integer or string. * @param mixed $variable Reference to PHP variable containing the value. * @param mixed $type OPTIONAL Datatype of SQL parameter. * @param mixed $length OPTIONAL Length of SQL parameter. * @param mixed $options OPTIONAL Other options. * @return bool * @throws Zend_Db_Statement_Exception */ protected function _bindParam($parameter, &$variable, $type = null, $length = null, $options = null) { try { if ($type === null) { if (is_bool($variable)) { $type = PDO::PARAM_BOOL; } elseif ($variable === null) { $type = PDO::PARAM_NULL; } elseif (is_integer($variable)) { $type = PDO::PARAM_INT; } else { $type = PDO::PARAM_STR; } } return $this->_stmt->bindParam($parameter, $variable, $type, $length, $options); } catch (PDOException $e) { require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage()); } }