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); } }
/** * 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; }
function __construct(SblamBase $base, PDOStatement $pdo) { $this->base = $base; $this->pdo = $pdo; $pdo->setFetchMode(PDO::FETCH_ASSOC); $this->next(); }
/** * @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; }
private function bindValues(\PDOStatement $stmt, array $values) { foreach ($values as $key => $value) { $stmt->bindValue($key, $value, self::types[$key]); } return $stmt; }
public static function execute(\PDOStatement $stmt) { if ($stmt->execute()) { return true; } return false; }
public function dispose() { if (!$this->is_disposed) { $this->statement->closeCursor(); $this->is_disposed = true; } }
/** * @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); }
/** * @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)); } } }
function getLine() { if (!$this->_result) { return false; } return $this->_result->fetch(PDO::FETCH_ASSOC); }
/** * 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; }
/** * Prefetch data */ protected function prefetch() { if (!$this->currentFetched) { $this->currentData = $this->statement->fetch(); $this->currentFetched = true; } }
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; }
/** * @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; }
/** * 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)); } }
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(); }
/** * @param string $dbObjectName * * @return array */ public function fetchAll($dbObjectName = '') { if ('' === $dbObjectName) { $dbObjectName = $this->_objectName; } return $this->_statement->fetchAll(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $dbObjectName); }
/** * @param array|null $parameters * @param bool|null $disableQueryBuffering * @throws CM_Db_Exception * @return CM_Db_Result */ public function execute(array $parameters = null, $disableQueryBuffering = null) { $disableQueryBuffering = (bool) $disableQueryBuffering; $retryCount = 1; for ($try = 0; true; $try++) { try { if ($disableQueryBuffering) { $this->_client->setBuffered(false); } @$this->_pdoStatement->execute($parameters); if ($disableQueryBuffering) { $this->_client->setBuffered(true); } CM_Service_Manager::getInstance()->getDebug()->incStats('mysql', $this->getQueryString()); return new CM_Db_Result($this->_pdoStatement); } catch (PDOException $e) { if ($try < $retryCount && $this->_client->isConnectionLossError($e)) { $this->_client->disconnect(); $this->_client->connect(); $this->_reCreatePdoStatement(); continue; } throw new CM_Db_Exception('Cannot execute SQL statement', null, ['tries' => $try, 'originalExceptionMessage' => $e->getMessage(), 'query' => $this->_pdoStatement->queryString]); } } throw new CM_Db_Exception('Line should never be reached'); }
/** * <b>Não é passado com os Joins</b> * * @return array[Objetos] */ public function findAll() { $sql = "SELECT * FROM {$this->Table}"; $this->Stmt = Conn::prepare($sql); $this->Stmt->execute(); return $this->Stmt->fetchAll(); }
public static function executeFetchAllStatement(\PDOStatement $stmt) { if (!$stmt->execute()) { return []; } return $stmt->fetchAll(\PDO::FETCH_ASSOC); }
/** * Получение объекта из запроса * @return Item */ public function fetchObject(\PDOStatement $statement) { $statement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $this->getItemClass(), array($this->getManager(), $this->getTable(), false)); /** @var Item $obj */ $obj = $statement->fetch(); return $obj; }
protected function getItem(\PDOStatement $stmt) { $data = $stmt->fetch(\PDO::FETCH_ASSOC); if ($data) { return new static($this->pdo, $data); } return null; }
/** @param PDOStatement $query_result */ private function treat_success($query_result) { $result_array = array(); while ($query_obj = $query_result->fetchObject()) { $result_array[] = $query_obj; } parent::set_result('result_array', $result_array); }
/** * Tries to execute a statement, throw an explicit exception on failure */ protected function execute(\PDOStatement $query, array $variables = array()) { if (!$query->execute($variables)) { $errors = $query->errorInfo(); throw new ModelException($errors[2]); } return $query; }
/** * Récupère un résultat exactement */ protected function fetchOne(\PDOStatement $query) { if ($query->rowCount() != 1) { return false; } else { return $query->fetch(); } }
/** * * @param \PDOStatement $statement * @return array */ protected function statementToArray(\PDOStatement $statement) { $result = []; while ($row = $statement->fetch(\PDO::FETCH_OBJ)) { $result[] = $row; } return $result; }
public function __construct($message, PDOStatement $statement) { $infos = array(); foreach ($statement->errorInfo() as $key => $info) { $infos[] = $key . ': ' . $info; } parent::__construct($message . '. (ERRNO ' . $statement->errorCode() . ') ' . implode('<br />', $infos)); }
/** @param PDOStatement $query_result */ private function treat_success($query_result) { if ($query_result->rowCount() > 0) { (new Insert_user_dummy(array('id_user' => $this->connected, 'id_dummy' => TTransaction::get_last_inserted_id())))->run(); } else { TTransaction::rollback(); } }
/** @param PDOStatement $query_result */ private function treat_success($query_result) { if ($query_result->rowCount() > 0) { (new Delete_invitation(array('id' => parent::get_input('id_invitation'))))->run(); } else { TTransaction::rollback(); } }
public function formatOne(PDOStatement $stmt) { if ($stmt->rowCount() == 0) { return null; } else { return $stmt; } }