本文整理汇总了PHP中PDOStatement::rowCount方法的典型用法代码示例。如果您正苦于以下问题:PHP PDOStatement::rowCount方法的具体用法?PHP PDOStatement::rowCount怎么用?PHP PDOStatement::rowCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDOStatement
的用法示例。
在下文中一共展示了PDOStatement::rowCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param \PDOStatement $pdoStatement
* @param string $classname optional
*/
public function __construct($pdoStatement, $classname = '\\StdClass')
{
$this->pdoStatement = $pdoStatement;
$this->count = $this->pdoStatement->rowCount();
$this->classname = $classname;
$this->pdoStatement->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $this->classname);
}
示例2: _fetchAll
protected function _fetchAll()
{
switch ($this->_fetchMode) {
case self::FETCH_DATAOBJECT:
self::$_stmt->setFetchMode(PDO::FETCH_ASSOC);
$rowset = new \SplFixedArray(self::$_stmt->rowCount());
$rowClass = $this->_fetchArgument;
foreach (self::$_stmt as $index => $data) {
$rowset[$index] = new $rowClass($data, true, $this->_ctorArgs);
}
return $rowset;
case self::FETCH_CLASSFUNC:
self::$_stmt->setFetchMode(PDO::FETCH_ASSOC);
$rowset = new \SplFixedArray(self::$_stmt->rowCount());
$classFunc = $this->_fetchArgument;
foreach (self::$_stmt as $index => $data) {
$rowClass = $classFunc($data);
$rowset[$index] = new $rowClass($data, true, $this->_ctorArgs);
}
return $rowset;
default:
if (isset($this->_ctorArgs)) {
return self::$_stmt->fetchAll($this->_fetchMode, $this->_fetchArgument, $this->_ctorArgs);
}
if (isset($this->_fetchArgument)) {
return self::$_stmt->fetchAll($this->_fetchMode, $this->_fetchArgument);
}
if (isset($this->_fetchMode)) {
return self::$_stmt->fetchAll($this->_fetchMode);
}
}
}
示例3: treat_success
/**
* @param PDOStatement $query_result
*/
private function treat_success($query_result)
{
if ($query_result->rowCount() > 1) {
parent::set_error(1, "Mais de um item foi removido, assim, a remoção foi cancelada.");
TTransaction::rollback();
} elseif ($query_result->rowCount() == 0) {
parent::set_error(1, "Nenhum item foi removido.");
}
}
示例4: getResultList
/**
* @param $entityClass
* @return array
*/
public function getResultList($entityClass)
{
$this->sqlStatement->execute($this->params);
if ($this->sqlStatement->rowCount() > 0) {
$entities = array();
$rows = $this->sqlStatement->fetchAll();
foreach ($rows as $row) {
/** @var Entity $entity */
$entity = new $entityClass($this);
$entity->init($row);
array_push($entities, $entity);
}
return $entities;
}
return array();
}
示例5: affectedRows
public function affectedRows()
{
if (empty($this->lastStatement)) {
return 0;
}
return $this->lastStatement->rowCount();
}
示例6: execute
/**
* @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;
}
示例7: num_rows
/**
* Devolvemos la cantidad de filas afectadas por la consulta
*
* @todo Ver resultado en algunos tipos de base de datos que no retornan
* el resultado esperado.
*
* @author Ignacio Daniel Rostagno <ignaciorostagno@vijona.com.ar>
* @return int
*/
public function num_rows()
{
if ($this->cant === NULL) {
$this->cant = $this->query->rowCount();
}
return $this->cant;
}
示例8: getLastRowCount
/**
* @return int
*/
public function getLastRowCount()
{
if (!$this->lastPdoStatement) {
return null;
}
return $this->lastPdoStatement->rowCount();
}
示例9: debugger
private function debugger()
{
if ($this->fpdo->debug) {
if (!is_callable($this->fpdo->debug)) {
$backtrace = '';
$query = $this->getQuery();
$parameters = $this->getParameters();
$debug = '';
if ($parameters) {
$debug = "# parameters: " . implode(", ", array_map(array($this, 'quote'), $parameters)) . "\n";
}
$debug .= $query;
$pattern = '(^' . preg_quote(dirname(__FILE__)) . '(\\.php$|[/\\\\]))';
// can be static
foreach (debug_backtrace() as $backtrace) {
if (isset($backtrace["file"]) && !preg_match($pattern, $backtrace["file"])) {
// stop on first file outside FluentPDO source codes
break;
}
}
$time = sprintf('%0.3f', $this->time * 1000) . ' ms';
$rows = $this->result ? $this->result->rowCount() : 0;
fwrite(STDERR, "# {$backtrace['file']}:{$backtrace['line']} ({$time}; rows = {$rows})\n{$debug}\n\n");
} else {
call_user_func($this->fpdo->debug, $this);
}
}
}
示例10: debugger
/**
* Echo/pass a debug string
*/
private function debugger()
{
if ($this->fpdo->debug) {
if (!is_callable($this->fpdo->debug)) {
$backtrace = '';
$query = $this->getQuery();
$parameters = $this->getParameters();
$debug = '';
if ($parameters) {
$debug = '# parameters: ' . implode(', ', array_map(array($this, 'quote'), $parameters)) . "\n";
}
$debug .= $query;
$pattern = '(^' . preg_quote(__DIR__) . '(\\.php$|[/\\\\]))';
// can be static
foreach (debug_backtrace() as $backtrace) {
if (isset($backtrace['file']) && !preg_match($pattern, $backtrace['file'])) {
// stop on first file outside FluentPDO source codes
break;
}
}
$time = sprintf('%0.3f', $this->time * 1000) . ' ms';
$rows = $this->result ? $this->result->rowCount() : 0;
$finalString = "# {$backtrace['file']}:{$backtrace['line']} ({$time}; rows = {$rows})\n{$debug}\n\n";
if (is_resource(STDERR)) {
// if STDERR is set, send there, otherwise just output the string
fwrite(STDERR, $finalString);
} else {
echo $finalString;
}
} else {
call_user_func($this->fpdo->debug, $this);
}
}
}
示例11: rowCount
public function rowCount()
{
if ($this->_statement instanceof \PDOStatement) {
return $this->_statement->rowCount();
}
return null;
}
示例12: numRows
/**
* Gets number of rows returned by a resulset
*
*<code>
* $result = $connection->query("SELECT * FROM robots ORDER BY name");
* echo 'There are ', $result->numRows(), ' rows in the resulset';
*</code>
*
* @return int
*/
public function numRows()
{
$rowCount = $this->_rowCount;
if ($rowCount === false) {
switch ($this->_connection->getType()) {
case 'mysql':
$rowCount = $this->_pdoStatement->rowCount();
break;
case 'pgsql':
$rowCount = $this->_pdoStatement->rowCount();
break;
}
if ($rowCount === false) {
//SQLite/Oracle/SQLServer returns resultsets that to the client eyes (PDO) has an
//arbitrary number of rows, so we need to perform an extra count to know that
$sqlStatement = $this->_sqlStatement;
//If the sql_statement starts with SELECT COUNT(*) we don't make the count
if (strpos($sqlStatement, 'SELECT COUNT(*) ') !== 0) {
$bindParams = $this->_bindParams;
$bindTypes = $this->_bindTypes;
$matches = null;
if (preg_match("/^SELECT\\s+(.*)\$/i", $sqlStatement, $matches) == true) {
$rowCount = $this->_connection->query("SELECT COUNT(*) \"numrows\" FROM (SELECT " . $matches[0] . ')', $bindParams, $bindTypes)->fetch()->numRows();
}
} else {
$rowCount = 1;
}
}
//Update the value to avoid further calculations
$this->_rowCount = $rowCount;
}
return $rowCount;
}
示例13: getAffectedRows
/**
* Returns the number of rows affected by the last SQL statement
*
* @return int the number of rows.
*/
public function getAffectedRows()
{
$affectedRows = 0;
if (!is_null($this->resourceHandle)) {
$affectedRows = $this->resourceHandle->rowCount();
}
return $affectedRows;
}
示例14:
/**
* Get affected rows from last SQL query
* @return integer
*/
function affected_rows()
{
if ($this->connected !== true || $this->res === null) {
return false;
} else {
return $this->res->rowCount();
}
}
示例15: getAffectedRows
/**
* Counts number of affected rows by the last sql statement (INSERT, UPDATE or DELETE).
*
* @return integer number of affected rows
*/
public function getAffectedRows() {
try {
return $this->pdoStatement->rowCount();
}
catch (\PDOException $e) {
throw new DatabaseException("Can not fetch affected rows: ".$e->getMessage(), $this);
}
}