本文整理汇总了PHP中PDOStatement类的典型用法代码示例。如果您正苦于以下问题:PHP PDOStatement类的具体用法?PHP PDOStatement怎么用?PHP PDOStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PDOStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertToNativeTypes
/**
* Converts columns from strings to types according to
* PDOStatement::columnMeta
* http://stackoverflow.com/a/9952703/3006989
*
* @param PDOStatement $st
* @param array $assoc returned by PDOStatement::fetch with PDO::FETCH_ASSOC
* @return copy of $assoc with matching type fields
*/
public static function convertToNativeTypes(PDOStatement $statement, $rows)
{
for ($i = 0; $columnMeta = $statement->getColumnMeta($i); $i++) {
$type = $columnMeta['native_type'];
switch ($type) {
case 'DECIMAL':
case 'TINY':
case 'SHORT':
case 'LONG':
case 'LONGLONG':
case 'INT24':
if (isset($rows[$columnMeta['name']])) {
$rows[$columnMeta['name']] = $rows[$columnMeta['name']] + 0;
} else {
if (is_array($rows) || $rows instanceof Traversable) {
foreach ($rows as &$row) {
if (isset($row[$columnMeta['name']])) {
$row[$columnMeta['name']] = $row[$columnMeta['name']] + 0;
}
}
}
}
break;
case 'DATETIME':
case 'DATE':
case 'TIMESTAMP':
// convert to date type?
break;
// default: keep as string
}
}
return $rows;
}
示例2: __construct
function __construct(SblamBase $base, PDOStatement $pdo)
{
$this->base = $base;
$this->pdo = $pdo;
$pdo->setFetchMode(PDO::FETCH_ASSOC);
$this->next();
}
示例3: execute
/**
* @see \PDOStatement::execute
*/
public function execute(array $input_parameters = array())
{
$start = microtime(true);
$result = $this->statement->execute($input_parameters);
$this->pdo->addLog(array('query' => $this->statement->queryString, 'time' => microtime(true) - $start, 'values' => array_merge($this->binds, $input_parameters)));
return $result;
}
示例4: bindValues
private function bindValues(\PDOStatement $stmt, array $values)
{
foreach ($values as $key => $value) {
$stmt->bindValue($key, $value, self::types[$key]);
}
return $stmt;
}
示例5: execute
public static function execute(\PDOStatement $stmt)
{
if ($stmt->execute()) {
return true;
}
return false;
}
示例6: bind
/**
* @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));
}
}
}
示例7: preforward
/**
* CSVを出力する
* @access public
* @param CSVWriter $writer CSV書き込みクラス
* @param PDOStatement|array $sth 出力する値
* @param string $filename 出力するCSV名
* @see Admin_ViewClass::preforward
*/
function preforward($writer, $sth, $filename)
{
//CSV出力
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Type: text/csv;charset=SJIS-win');
$writer->charset = 'SJIS-win';
// 取得結果が0件の場合のヘッダ出力用
// $result = $sth->fetchAll();
// if(count($result)==0){
// $result=(array(0));
// }
// foreach ($result as $r) {
// $writer->write($r);
// }
$row = array();
$count = 0;
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$count++;
$writer->write($row);
}
if (0 == $count) {
$writer->write($row);
}
exit;
}
示例8: 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);
}
}
示例9: rewind
function rewind()
{
$this->PDOStatement = $this->pdo->prepare($this->sql . ' ' . $this->ordersql . ' ' . $this->limitsql);
$this->PDOStatement->execute($this->params);
$this->PDOStatement->setFetchMode(PDO::FETCH_ASSOC);
$this->position = 0;
}
示例10: get_row
/**
* @param PDOStatement $stm
* @param array $data
* @return array
*/
protected function get_row(PDOStatement $stm, array $data = array())
{
$data ? $stm->execute($data) : $stm->execute();
$stm->setFetchMode(PDO::FETCH_ASSOC);
$var = $stm->fetch();
return $var;
}
示例11: bindParameters
/**
* 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));
}
}
示例12: bindValueAndExecuteInsertOrUpdate
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();
}
示例13: executeFetchAllStatement
public static function executeFetchAllStatement(\PDOStatement $stmt)
{
if (!$stmt->execute()) {
return [];
}
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
示例14: dispose
public function dispose()
{
if (!$this->is_disposed) {
$this->statement->closeCursor();
$this->is_disposed = true;
}
}
示例15: next
/**
* @inheritDoc
*/
public function next()
{
$this->cursorOffset++;
// Fetching one row, located at the given offset in the result set
// (This is what PDO::FETCH_ORI_ABS is for).
$this->currentRow = $this->statement->fetch(\PDO::FETCH_ASSOC, \PDO::FETCH_ORI_ABS, $this->cursorOffset);
}