/** * Number of rows in the result set * * @return int */ public function num_rows() { if (is_int($this->num_rows)) { return $this->num_rows; } elseif (count($this->result_array) > 0) { return $this->num_rows = count($this->result_array); } elseif (count($this->result_object) > 0) { return $this->num_rows = count($this->result_object); } elseif (($num_rows = $this->result_id->rowCount()) > 0) { return $this->num_rows = $num_rows; } return $this->num_rows = count($this->result_array()); }
/** * @method _parseResults() * @access private * @throws Exception * @desc Parsea los resultados obtenidos en cualquier ejecución de consultas SQL. * @see self::_throwModelException() */ private function _parseResults() { $this->_resultSet = array(); $statementWords = explode(' ', $this->_sqlQuery); if (preg_match('/SELECT/', strtoupper($statementWords[0]))) { $statement = $this->_PDOmySQLConn->prepare($this->_sqlQuery); $statement->execute(); $this->_numRows = $statement->rowCount(); if ((int) $this->_numRows > 0) { while ($row = $this->_resource->fetch(PDO::FETCH_ASSOC)) { array_push($this->_resultSet, $row); } } } else { $this->_numRows = $this->_resource->rowCount(); } }
/** * Constructor. * Initializes the connection and launches the query. * * @param string $sql The sql statement * @param string $dsn The database dsn * @param string $user The database user * @param string $pass The database password * @return void * @access public */ public function __construct($sql = '', $dsn = APPLICATION_DB_DSN, $user = APPLICATION_DB_USER, $pass = APPLICATION_DB_PASSWORD) { $this->_sql = trim($sql); $this->_connect($dsn, $user, $pass); if ($this->_sql && $this->_db) { /*only for stats*/ if (STATS_DEBUG) { $time_start = CMS_stats::getmicrotime(); } if (preg_match("#^(insert|update)#i", $this->_sql)) { $this->_numRows = $this->_db->exec($this->_sql); if (preg_match("#^insert#i", $this->_sql)) { $this->_lastInsertedID = $this->_db->lastInsertId(); } $errorInfos = $this->_db->errorInfo(); if (isset($errorInfos[2])) { $clean_sql = str_replace("\n", "", $this->_sql); $clean_sql = preg_replace("#\t+#", " ", $clean_sql); $errorInfo = isset($errorInfos[2]) ? $errorInfos[2] : 'No error returned'; $this->raiseError('Database querying failed : ' . $errorInfo . "\nQuery : " . $clean_sql); } } else { $this->_result = $this->_db->query($this->_sql); if ($this->_result) { $this->_numRows = $this->_result->rowCount(); } else { $clean_sql = str_replace("\n", "", $this->_sql); $clean_sql = preg_replace("#\t+#", " ", $clean_sql); $errorInfos = $this->_db->errorInfo(); $errorInfo = isset($errorInfos[2]) ? $errorInfos[2] : 'No error returned'; $this->raiseError('Database querying failed : ' . $errorInfo . "\nQuery : " . $clean_sql . "\nFrom : " . io::getCallInfos(3)); } } /*only for stats*/ if (STATS_DEBUG) { $currenttime = CMS_stats::getmicrotime(); $time = $currenttime - $time_start; if (VIEW_SQL) { CMS_stats::$sqlTable[] = array('sql' => $this->_sql, 'time' => $time, 'current' => $currenttime - CMS_stats::$timeStart, 'from' => io::getCallInfos(3), 'memory' => memory_get_usage(), 'peak' => memory_get_peak_usage()); } CMS_stats::$sqlNbRequests++; CMS_stats::$totalTime += $time; } } }
/** * Numero de Filas afectadas en un insert, update o delete * * @param resource $pdo_statement * @deprecated * @return int */ public function affected_rows($pdo_statement = NULL) { if (!$this->pdo) { throw new KumbiaException('No hay conexión para realizar esta acción'); } if ($pdo_statement) { try { $row_count = $pdo_statement->rowCount(); if ($row_count === false) { throw new KumbiaException($this->error(" al ejecutar <em>\"{$sql_query}\"</em>")); } return $row_count; } catch (PDOException $e) { throw new KumbiaException($this->error($e->getMessage())); } } else { return $this->affected_rows; } }
/** * Get the number of returned rows for the previous executed SQL statement. * * @param resource $cursor An optional database cursor resource to extract the row count from. * * @return integer The number of returned rows. * * @since 12.1 */ public function getNumRows($cursor = null) { $this->connect(); if ($cursor instanceof PDOStatement) { return $cursor->rowCount(); } elseif ($this->prepared instanceof PDOStatement) { return $this->prepared->rowCount(); } else { return 0; } }
/** * Get the number of returned rows for the previous executed SQL statement. * * @param resource $cursor An optional database cursor resource to extract the row count from. * * @return integer The number of returned rows. */ public function getNumRows($cursor = null) { if ($cursor instanceof \PDOStatement) { return $cursor->rowCount(); } if ($this->cursor instanceof \PDOStatement) { return $this->cursor->rowCount(); } return 0; }
/** * Get number of rows in result * * @param resource $result the resource containing the number of rows * * @return int the number of rows to return * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. */ public function getRowsNum($result) { Xoops::getInstance()->deprecated('getRowsNum is deprecated and not dependable.'); //$this->deprecated(); return $result->rowCount(); }
/** * 取出最后一次查询影响的行数 * * @param resource $resource 查询的资源数据 * @param mixed $handle 连接对象 * @return integer */ public function affectedRows($resource, $handle) { return $resource->rowCount(); }
/** * Fetch number of rows in a query result. * * @param resource $sth * PDOStatement resource. * * @return int */ public function numRows($sth) { return $sth->rowCount(); }
/** * Get the number of returned rows for the previous executed SQL statement. * * @param resource $cursor An optional database cursor resource to extract the row count from. * * @return integer The number of returned rows. * * @since 11.1 */ public function getNumRows($cursor = null) { return $cursor ? $cursor->rowCount() : $this->cursor->rowCount(); }
/** * Returns the number of affected rows. * * @return int Returns the number of affected rows. */ public function getAffectedRows() { return $this->result->rowCount(); }
/** * Get the affected count from the database. * * @param resource $resource * * @return int */ function db_driver_affected_count($resource) { global $_db; return $resource->rowCount(); }