本文整理汇总了PHP中PDOStatement::bindParam方法的典型用法代码示例。如果您正苦于以下问题:PHP PDOStatement::bindParam方法的具体用法?PHP PDOStatement::bindParam怎么用?PHP PDOStatement::bindParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDOStatement
的用法示例。
在下文中一共展示了PDOStatement::bindParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bind
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);
}
}
示例2: bindParam
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);
}
}
示例3: bindParam
/**
* 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);
}
}
示例4: bindParametersFromContainer
/**
* 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);
}
}
示例5: bindParametersFromContainer
/**
* 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);
}
}
示例6: Execute
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;
}
}
示例7: execute
/**
* 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;
}
示例8: bindParam
/**
* 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);
}
示例9: bindParam
/**
* {@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);
}
}
示例10: executeStatement
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;
}
示例11: _bindParam
/**
* 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());
}
}
示例12: bindParam
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);
}
示例13: query
/**
* 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;
}
示例14: bindValues
/**
* 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;
}
示例15: bind
/**
* @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);
}
}
}