public function bindParams($params = []) { foreach ($params as $param => $value) { $this->stmt->bindValue($param, $value); } return $this->stmt; }
private function bindValueAndExecuteInsertOrUpdate(PDOStatement $stm, Contact $contact) { $stm->bindValue(':name', $contact->getName(), PDO::PARAM_STR); $stm->bindValue(':photo', $contact->getPhoto(), PDO::PARAM_STR); $stm->bindValue(':email', $contact->getEmail(), PDO::PARAM_STR); return $stm->execute(); }
public function __construct(Connection $connection, $queryString, array $params) { $time = microtime(TRUE); $this->connection = $connection; $this->supplementalDriver = $connection->getSupplementalDriver(); $this->queryString = $queryString; $this->params = $params; try { if (substr($queryString, 0, 2) === '::') { $connection->getPdo()->{substr($queryString, 2)}(); } elseif ($queryString !== NULL) { static $types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL]; $this->pdoStatement = $connection->getPdo()->prepare($queryString); foreach ($params as $key => $value) { $type = gettype($value); $this->pdoStatement->bindValue(is_int($key) ? $key + 1 : $key, $value, isset($types[$type]) ? $types[$type] : PDO::PARAM_STR); } $this->pdoStatement->setFetchMode(PDO::FETCH_ASSOC); $this->pdoStatement->execute(); } } catch (\PDOException $e) { $e = $this->supplementalDriver->convertException($e); $e->queryString = $queryString; throw $e; } $this->time = microtime(TRUE) - $time; }
protected function bindFields(\PDOStatement $statment, File $file) { $statment->bindValue(':fileName', $file->getFileName()); $statment->bindValue(':fileType', $file->getFileType()); $statment->bindValue(':fileSize', $file->getFileSize()); $statment->bindValue(':fileMediaInfo', $file->getFileMediaInfo()); $statment->bindValue(':fileKey', $file->getFileKey()); }
/** * Constructor * * @param PDO $pdo Database connection * @param string $sql SQL statement * @param array $params SQL statement parameters */ public function __construct(\PDO $pdo, $sql, array $params = array()) { $this->pdo = $pdo; $this->statement = $this->pdo->prepare($sql); foreach ($params as $key => $value) { $this->statement->bindValue($key, $value); } }
public function bindValue($parameter, $value, $dataType = null) { if ($dataType === null) { $dataType = $this->getPdoType($value); } $this->statement->bindValue($parameter, $value, $dataType); return $this; }
/** * @param int $zoom_level * @param int $x * @param int $y * @param string $data */ public function addTile($zoom_level, $x, $y, $data) { $this->addTileStmt->bindValue(':z', $zoom_level, \PDO::PARAM_INT); $this->addTileStmt->bindValue(':x', $x, \PDO::PARAM_INT); $this->addTileStmt->bindValue(':y', $y, \PDO::PARAM_INT); $this->addTileStmt->bindValue(':data', $data, \PDO::PARAM_LOB); $this->addTileStmt->execute(); }
protected function bindParams(array $params, $types) { foreach ($params as $key => $param) { $type = isset($this->type[$types[$key]]) ? $this->type[$types[$key]] : PDO::PARAM_STR; // Placeholder numbers begins from 1 $this->stmt->bindValue($key + 1, $param, $type); } }
private function setParameters() { if (isset($this->binds) && !empty($this->binds)) { foreach ($this->binds as $index => $value) { $this->delete->bindValue(":{$index}", $value, is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR); } } }
/** * Associe les valeurs aux paramètres de la requète * * @param PDOStatement $stmt le statement préparé avec la requète sql * @param array $values les valeurs à associer * @return type le statement avec toutes les associations de faites */ private function bindValueHelper($stmt, $values) { $stmt->bindValue(':title', $values['title'], PDO::PARAM_STR); $stmt->bindValue(':short_desc', $values['short_desc'], PDO::PARAM_STR); $stmt->bindValue(':long_desc', $values['long_desc'], PDO::PARAM_STR); $stmt->bindValue(':director', $values['director'], PDO::PARAM_STR); $stmt->bindValue(':year', $values['year'], PDO::PARAM_STR); $stmt->bindValue(':image', $values['image'], PDO::PARAM_STR); return $stmt; }
/** * For every tile needed, this function will be called * * Return the blob of this image * @param Tile $tile * @throws TileNotAvailableException * @return string Blob of this image */ public function getTile(Tile $tile) { $this->tile_fetcher->bindValue(':x', $tile->x); $this->tile_fetcher->bindValue(':y', $tile->y); $this->tile_fetcher->execute(); $tile_data = $this->tile_fetcher->fetchColumn(); if ($tile_data === false) { throw new TileNotAvailableException(); } return $tile_data; }
private function getSyntax() { if ($this->Places) { foreach ($this->Places as $Vinculo => $Valor) { if ($Vinculo == 'limit' || $Vinculo == 'offset') { $Valor = (int) $Valor; } $this->Read->bindValue(":{$Vinculo}", $Valor, is_int($Valor) ? PDO::PARAM_INT : PDO::PARAM_STR); } } }
private function getSyntax() { if ($this->Places) { foreach ($this->Places as $Bind => $Value) { if ($Bind == 'limit' || $Bind == 'offset') { $Value = (int) $Value; } $this->Read->bindValue(":{$Bind}", $Value, is_int($Value) ? PDO::PARAM_INT : PDO::PARAM_STR); } } }
/** * doSetSystemFields * * @param PDOStatement $stmt * @param KVDdom_DomainObject $domaiObject * @param integer $startIndex * @return integer Volgende te gebruiken index. */ public function doSetSystemFields($stmt, $domainObject, $startIndex) { if (!$domainObject->hasSystemFields()) { throw new LogicException('Kan de systemFields van een object dat geen systemFields heeft niet instellen op een statement.'); } $stmt->bindValue($startIndex++, $domainObject->getSystemFields()->getAangemaaktDoor(), PDO::PARAM_STR); $stmt->bindValue($startIndex++, $domainObject->getsystemFields()->getAangemaaktOp()->format(DATE_ISO8601), PDO::PARAM_STR); $stmt->bindValue($startIndex++, $domainObject->getSystemFields()->getTargetVersie(), PDO::PARAM_INT); $stmt->bindValue($startIndex++, $domainObject->getSystemFields()->getBewerktDoor(), PDO::PARAM_STR); $stmt->bindValue($startIndex++, $domainObject->getSystemFields()->getBewerktOp()->format(DATE_ISO8601), PDO::PARAM_STR); return $startIndex; }
private function getSyntax() { if ($this->Places) { foreach ($this->Places as $Vinculo => $Valor) { if ($Vinculo == 'limit' || $Vinculo == 'offset') { //limit e offset no SQL precisa ser int. Portanto, troca-se o tipo de dados de STRING para INT $Valor = (int) $Valor; } $this->Read->bindValue(":{$Vinculo}", $Valor, is_int($Valor) ? PDO::PARAM_INT : PDO::PARAM_STR); } } }
protected function bindValues(\PDOStatement $stmt) { $request = $this->getRequest(); $stmt->bindValue(1, $request->getClientIp()); $stmt->bindValue(2, $request->get('User')); if (strpos(strtoupper($this->getCommandName()), 'ALL') > 0) { $stmt->bindValue(3, $request->get('Consulta')); return; } $stmt->bindValue(3, $request->get('ID')); $stmt->bindValue(4, $request->get('Consulta')); }
/** * @method execute * @param $query|string * @return DataBase */ public function execute($query) { $this->error = false; if ($query) { if ($this->query = $this->pdo->prepare($this->escapeDoubleSpaces($query))) { if (count($this->paramArray)) { foreach ($this->paramArray as $param => $val) { if (is_null($val)) { $var = PDO::PARAM_NULL; } elseif (is_int($val)) { $var = PDO::PARAM_INT; } elseif (is_bool($val)) { $var = PDO::PARAM_BOOL; } else { $var = PDO::PARAM_STR; if ($this->queryType === self::QUERY_TYPE_UPDATE) { $val = $this->wrapInSingleQuotes($val); } } $this->query->bindValue($param, $val, $var); } #End Foreach } if ($this->query->execute()) { $this->results = $this->query->fetchAll(PDO::FETCH_OBJ); $this->count = $this->query->rowCount(); } else { $this->error = true; } } } $this->reset(); return $this; }
/** * prepare a statement and bind parameters * * @param string $statementString * @param array $parameters * * @return void */ private function primeQuery($statementString, array $parameters) { $this->statement = $this->connection->prepare($statementString); foreach ($parameters as $name => $value) { // question mark placeholders start with 1 if (is_int($name)) { ++$name; } else { $name = ':' . ltrim($name, ':'); } // set parameter types, depending on parameter values $type = \PDO::PARAM_STR; if (is_bool($value)) { $type = \PDO::PARAM_BOOL; } else { if (is_int($value)) { $type = \PDO::PARAM_INT; } else { if (is_null($value)) { $type = \PDO::PARAM_NULL; } } } $this->statement->bindValue($name, $value, $type); } }
public function bindValue($pos, $value, $type = PDO::PARAM_STR) { $type_name = isset(self::$_typeMap[$type]) ? self::$_typeMap[$type] : 'PDO::PARAM_STR'; $this->_params[] = array($pos, $value, $type_name); $result = parent::bindValue($pos, $value, $type); return $result; }
/** * Binds the resolved parameters to the supplied PDO statement. * * @param \PDOStatement $statement * @param IResolvedParameterRegistry $resolvedParameters * * @return void */ public function bindParameters(\PDOStatement $statement, IResolvedParameterRegistry $resolvedParameters) { $resolvedExpressions = $this->parameters->resolve($resolvedParameters); foreach ($resolvedExpressions->getParameters() as $parameter) { $statement->bindValue($parameter->getData(), $resolvedExpressions->getValue($parameter)); } }
/** * @override */ public function bind(PDOStatement $stmt, $value) { $param = $value[0]; $param->__init__(); $logger = HermitLoggerManager::getLogger(); if ($logger->isDebugEnabled()) { $buf = ''; foreach ($this->bindKeys as $key) { $v = null; if ($param instanceof HermitParam) { $v = $param->get($key); } else { $method = $this->reflector->getMethod('get' . ucfirst($key)); $v = $method->invoke($param); } $buf .= $key . ' => ' . $v; $buf .= ', '; } $logger->debug('{%s} statement binds parameter {:key => param} = %s', __CLASS__, $buf); } foreach ($this->bindKeys as $index => $key) { if ($this->info->typeofIn($key)) { $stmt->bindValue(':' . $key, $param->get($key)); } } }
protected function bindEncodedParams() { foreach ($this->params as $k => $v) { $encoded = false; foreach ($this->encoders as $encoder) { $result = $encoder->encodeParam($this->conn, $v, $encoded); if ($encoded) { $v = $result; break; } } if ($v instanceof StreamInterface) { if (!$v->isReadable()) { throw new \InvalidArgumentException('Input stream must be readable to be used as DB input param'); } // FIXME: This is a workaround for PHP7 crashing with Sqlite LOB params bound to input streams... if ($this->conn->getDriverName() == DB::DRIVER_SQLITE && defined('PHP_MAJOR_VERSION') && PHP_MAJOR_VERSION > 5) { $this->stmt->bindValue($k, $v->getContents()); } else { $this->stmt->bindValue($k, (new StreamWrapper($v))->getResource(), \PDO::PARAM_LOB); } } elseif ($v instanceof UUID) { switch ($this->conn->getDriverName()) { case DB::DRIVER_MSSQL: case DB::DRIVER_POSTGRESQL: $this->stmt->bindValue($k, (string) $v); break; default: $this->stmt->bindValue($k, $v->toBinary()); } } else { $this->stmt->bindValue($k, $v); } } }
private function bindValues(\PDOStatement $stmt, array $values) { foreach ($values as $key => $value) { $stmt->bindValue($key, $value, self::types[$key]); } return $stmt; }
/** * Execute DB query. * Provides a fluent interface. * * @param string $sql Query text * @param array $queryParams Named parameters, like ['name' => $value] * * @return PDOMySQL * @throws Exception */ public function query($sql, array $queryParams = []) { if (!isset($this->link)) { $this->connect(); } $this->paramsIn = $queryParams; $this->paramsOut = []; if (strpos($sql, ':') !== false) { // Special case - table prefix $sql = str_replace(':p_', $this->prefix, $sql); // Find placeholders if (strpos($sql, ':') !== false) { // Skip string literals $pattern = '/(?:' . "'[^'\\\\]*(?:(?:\\\\.|'')[^'\\\\]*)*'" . '|"[^"\\\\]*(?:(?:\\\\.|"")[^"\\\\]*)*"' . '|`[^`\\\\]*(?:(?:\\\\.|``)[^`\\\\]*)*`' . ')(*SKIP)(*F)' . '|(?:\\:)([a-zA-Z][a-zA-Z0-9_]*)/'; // Custom placeholders $sql = preg_replace_callback($pattern, [$this, 'replace'], $sql); } } $this->result = $this->link->prepare($sql); foreach ($this->paramsOut as $i => $var) { $this->result->bindValue($i + 1, $var, is_integer($var) ? \PDO::PARAM_INT : \PDO::PARAM_STR); } $this->result->execute(); return $this; }
/** * Binds a value to a parameter * * @param mixed $parameter * @param mixed $value * @param int $dataType * * @return bool */ public function bindValue($parameter, $value, $dataType = PDO::PARAM_STR) { if ($this->trackDataType($dataType)) { $this->values[$this->parameter($parameter)] = $this->value($dataType, $value); } return parent::bindValue($parameter, $value, $dataType); }
public function bind(PDOStatement $stmt, $value) { $logger = HermitLoggerManager::getLogger(); if ($logger->isDebugEnabled()) { $buf = ''; foreach ($value as $obj) { foreach ($this->bindKeys as $key) { $v = null; if ($obj instanceof HermitParam) { $v = $obj->get($key); } else { $methodName = 'get' . ucfirst($key); if ($this->reflector->hasMethod($methodName)) { $method = $this->reflector->getMethod($methodName); $v = $method->invoke($obj); } else { if (!isset($obj->{$key})) { continue; } $v = $obj->{$key}; } } $buf .= $key . ' => ' . $v; $buf .= ', '; } } $logger->debug('{%s} statement binds parameter {:key => param} = %s', __CLASS__, $buf); } foreach ($value as $obj) { foreach ($this->bindKeys as $key) { if ($obj instanceof HermitParam) { $stmt->bindValue(':' . $key, $obj->get($key)); } else { $methodName = 'get' . ucfirst($key); if ($this->reflector->hasMethod($methodName)) { $method = $this->reflector->getMethod($methodName); $stmt->bindValue(':' . $key, $method->invoke($obj)); } else { if (!isset($obj->{$key})) { continue; } $stmt->bindValue(':' . $key, $obj->{$key}); } } } } }
/** * doSetSystemFields * * @param PDOStatement $stmt * @param KVDdom_DomainObject $domainObject * @param integer $startIndex * @return integer Volgende te gebruiken index. */ public function doSetSystemFields($stmt, $domainObject, $startIndex) { if (!$domainObject->hasSystemFields()) { throw new LogicException('Kan de systemFields van een object dat geen systemFields heeft niet instellen op een statement.'); } $stmt->bindValue($startIndex++, $domainObject->getSystemFields()->getTargetVersie(), PDO::PARAM_INT); return $startIndex; }
/** * {@inheritdoc} */ public function bindValue($param, $value, $type = \PDO::PARAM_STR) { try { return parent::bindValue($param, $value, $type); } catch (\PDOException $exception) { throw new PDOException($exception); } }
/** * Binds a value to a parameter. * * @param mixed $parameter Name the parameter, either integer or string. * @param mixed $value Scalar value to bind to the parameter. * @param mixed $type OPTIONAL Datatype of the parameter. * @return bool * @throws Zend_Db_Statement_Exception */ public function bindValue($parameter, $value, $type = null) { try { return $this->_stmt->bindValue($parameter, $value, $type); } catch (PDOException $e) { require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage()); } }
public function getStatement(\PDOStatement $statement) { $i = 0; foreach ($this->fields as $field) { $statement->bindValue(':' . $this->baseName . $i, $field, $this->type); $i++; } return $statement; }