/** * * @return integer number of rows updated */ public function rowCount() { if (!$this->_stmt) { return false; } $num = db2_num_rows($this->_stmt); if ($num === false) { throw new Zend_Db_Statement_Db2_Exception(db2_stmt_errormsg($this->_stmt), db2_stmt_error($this->_stmt)); } return db2_num_rows($this->_stmt); }
function insert() { $conn = $this->connect(); if ($conn == true) { $sql = "SELECT name from helloworld"; $stmt = db2_exec($conn, $sql); $num_rows = db2_num_rows($stmt); if ($num_rows == 0 || $num_rows == "") { $sql = "INSERT INTO helloworld(NAME) VALUES ('Hello World')"; $stmt = db2_exec($conn, $sql); } } }
function _initrs() { global $ADODB_COUNTRECS; $this->_numOfRows = $ADODB_COUNTRECS ? @db2_num_rows($this->_queryID) : -1; $this->_numOfFields = @db2_num_fields($this->_queryID); // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0 if ($this->_numOfRows == 0) { $this->_numOfRows = -1; } }
/** * Returns number of rows in previous resultset. If no previous resultset exists, * this returns false. * * @return integer Number of rows in resultset */ function lastNumRows() { if ($this->_result) { return db2_num_rows($this->_result); } return null; }
/** * Returns the number of rows affected by the last query or 0 * @return Integer: the number of rows affected by the last query */ public function affectedRows() { if (!is_null($this->mAffectedRows)) { // Forced result for simulated queries return $this->mAffectedRows; } if (empty($this->mLastResult)) { return 0; } return db2_num_rows($this->mLastResult); }
/** * Get affected rows * * @return integer */ public function getAffectedRows() { return db2_num_rows($this->resource); }
function dbi_affected_rows($conn, $res) { if (strcmp($GLOBALS['db_type'], 'mysql') == 0) { return mysql_affected_rows($conn); } elseif (strcmp($GLOBALS['db_type'], 'mysqli') == 0) { return $conn->affected_rows; } elseif (strcmp($GLOBALS['db_type'], 'mssql') == 0) { return mssql_rows_affected($conn); } elseif (strcmp($GLOBALS['db_type'], 'oracle') == 0) { return $GLOBALS['oracle_statement'] >= 0 ? OCIRowCount($GLOBALS['oracle_statement']) : -1; } elseif (strcmp($GLOBALS['db_type'], 'postgresql') == 0) { return pg_affected_rows($res); } elseif (strcmp($GLOBALS['db_type'], 'odbc') == 0) { return odbc_num_rows($res); } elseif (strcmp($GLOBALS['db_type'], 'ibm_db2') == 0) { return db2_num_rows($res); } elseif (strcmp($GLOBALS['db_type'], 'ibase') == 0) { return ibase_affected_rows($conn); } elseif (strcmp($GLOBALS['db_type'], 'sqlite') == 0) { return sqlite_changes($conn); } else { dbi_fatal_error('dbi_free_result (): ' . translate('db_type not defined.')); } }
/** * Returns the number of rows affected by the last INSERT, UPDATE or DELETE. * * <b>Note:</b> Use the {@link dbi_error()} function to get error information * if the connection fails. * * @param resource $conn The database connection * @param resource $res The database query resource returned from * the {@link dbi_query()} function. * * @return int The number or database rows affected. */ function dbi_affected_rows($conn, $res) { if (strcmp($GLOBALS["db_type"], "mysql") == 0) { return mysql_affected_rows($conn); } else { if (strcmp($GLOBALS["db_type"], "mysqli") == 0) { return mysqli_affected_rows($conn); } else { if (strcmp($GLOBALS["db_type"], "mssql") == 0) { return mssql_affected_rows($conn); } else { if (strcmp($GLOBALS["db_type"], "oracle") == 0) { if ($GLOBALS["oracle_statement"] >= 0) { return OCIRowCount($GLOBALS["oracle_statement"]); } else { return -1; } } else { if (strcmp($GLOBALS["db_type"], "postgresql") == 0) { return pg_affected_rows($res); } else { if (strcmp($GLOBALS["db_type"], "odbc") == 0) { return odbc_num_rows($res); } else { if (strcmp($GLOBALS["db_type"], "ibm_db2") == 0) { return db2_num_rows($res); } else { if (strcmp($GLOBALS["db_type"], "ibase") == 0) { return ibase_affected_rows($conn); } else { dbi_fatal_error("dbi_free_result(): db_type not defined."); } } } } } } } } }
/** * {@inheritdoc} */ public function lastNumRows() { return $this->result ? db2_num_rows($this->result) : false; }
public function execute($bind_params = false) { $ret_val = false; //---------------------------------------------- // Check Statement Resource //---------------------------------------------- if (!$this->stmt) { $this->gen_error('Invalid statement resource.'); return false; } //---------------------------------------------- // Check Bind Parameters //---------------------------------------------- if (!is_array($bind_params)) { $this->gen_error('Binding parameters must be passed as an array.'); return false; } $this->bind_params = $bind_params; //---------------------------------------------- // Execute Query //---------------------------------------------- $exec_status = @db2_execute($this->stmt, $bind_params); //---------------------------------------------- // Check for Errors //---------------------------------------------- if (!$exec_status) { if ($this->check_and_print_stmt_error($this->stmt)) { return false; } $this->gen_error('Prepared query execution failed.'); return false; } //---------------------------------------------- // Create Data Result Object if Necessary //---------------------------------------------- if ($this->stmt && gettype($this->stmt) != 'boolean') { //---------------------------------------------- // Affected Rows //---------------------------------------------- $this->affected_rows = db2_num_rows($this->stmt); $ret_val = $this->affected_rows; //---------------------------------------------- // Create Data Result Object //---------------------------------------------- $this->data_result = new data_result($this->stmt, $this->data_src); //---------------------------------------------- // Last Insert ID //---------------------------------------------- $this->last_id = db2_last_insert_id($this->handle); } //---------------------------------------------- // Return Data Result Object if it exists //---------------------------------------------- if ($this->data_result) { $this->num_rows = $this->data_result->num_rows(); $this->num_fields = $this->data_result->num_fields(); $ret_val = $this->data_result; } //---------------------------------------------- // Check for Errors //---------------------------------------------- if ($this->check_and_print_stmt_error($this->stmt)) { return false; } return $ret_val; }
/** * {@inheritdoc} */ public function rowCount() { return (int) @db2_num_rows($this->_stmt); }
public function set_num_rows() { $this->num_recs = db2_num_rows($this->resource); }
/** * Get number of rows affected by query * * @return int */ public function getAffectedRows() { switch ($this->model) { case "MYSQLI": $return = $this->handler->affected_rows; break; case "MYSQL_PDO": case "SQLITE_PDO": case "ORACLE_PDO": case "DBLIB_PDO": $return = $this->raw_data->rowCount(); break; case "DB2": $return = db2_num_rows($this->raw_data); break; case "POSTGRESQL": $return = pg_affected_rows($this->raw_data); break; } return $return; }
/** * {@inheritdoc} */ public function rowCount() { return @db2_num_rows($this->_stmt) ?: 0; }
/** * Number of rows in a result * * @param mixed $result * @return integer * @access public * @author Thorsten Rinne <*****@*****.**> * @since 2005-04-16 */ function numRows($result) { return db2_num_rows($result); }
/** * Returns the number of rows affected by the execution of the * last INSERT, DELETE, or UPDATE statement executed by this * statement object. * * @return int The number of rows affected. */ public function rowCount() { if (!$this->_stmt) { return false; } $num = @db2_num_rows($this->_stmt); if ($num === false) { return 0; } return $num; }
public function getAffectedRowCount($result) { return db2_num_rows($result); }
/** * Sets the number of rows affected by the query * * @param fResult $result The result object for the query * @param mixed $resource Only applicable for `ibm_db2`, `pdo`, `oci8` and `sqlsrv` extentions or `mysqli` prepared statements - this is either the `PDOStatement` object, `mysqli_stmt` object or the `oci8` or `sqlsrv` resource * @return void */ private function setAffectedRows($result, $resource = NULL) { if ($this->extension == 'ibm_db2') { $insert_update_delete = preg_match('#^\\s*(INSERT|UPDATE|DELETE)\\b#i', $result->getSQL()); $result->setAffectedRows(!$insert_update_delete ? 0 : db2_num_rows($resource)); } elseif ($this->extension == 'mssql') { $affected_rows_result = mssql_query('SELECT @@ROWCOUNT AS rows', $this->connection); $result->setAffectedRows((int) mssql_result($affected_rows_result, 0, 'rows')); } elseif ($this->extension == 'mysql') { $result->setAffectedRows(mysql_affected_rows($this->connection)); } elseif ($this->extension == 'mysqli') { if (is_object($resource)) { $result->setAffectedRows($resource->affected_rows); } else { $result->setAffectedRows(mysqli_affected_rows($this->connection)); } } elseif ($this->extension == 'oci8') { $result->setAffectedRows(oci_num_rows($resource)); } elseif ($this->extension == 'pgsql') { $result->setAffectedRows(pg_affected_rows($result->getResult())); } elseif ($this->extension == 'sqlite') { $result->setAffectedRows(sqlite_changes($this->connection)); } elseif ($this->extension == 'sqlsrv') { $result->setAffectedRows(sqlsrv_rows_affected($resource)); } elseif ($this->extension == 'pdo') { // This fixes the fact that rowCount is not reset for non INSERT/UPDATE/DELETE statements try { if (!$resource || !$resource->fetch()) { throw new PDOException(); } $result->setAffectedRows(0); } catch (PDOException $e) { // The SQLite PDO driver seems to return 1 when no rows are returned from a SELECT statement if ($this->type == 'sqlite' && $this->extension == 'pdo' && preg_match('#^\\s*SELECT#i', $result->getSQL())) { $result->setAffectedRows(0); } elseif (!$resource) { $result->setAffectedRows(0); } else { $result->setAffectedRows($resource->rowCount()); } } } }
/** * Transform database raw result in a standard array * * @param mixed $data Query result as returned from database handler * * @return array */ private function resultsToArray($data) { $result = array(); $id = false; $length = 0; $rows = 0; $iterator = 0; switch ($this->model) { case "MYSQLI": if ((!is_object($data) or !is_a($data, 'mysqli_result')) and $data != TRUE) { throw new DatabaseException('Invalid result data for model ' . $this->model); } switch ($this->fetch) { case 'NUM': $fetch = MYSQLI_NUM; break; case 'ASSOC': $fetch = MYSQLI_ASSOC; break; default: $fetch = MYSQLI_BOTH; break; } $this->length = is_object($data) ? $data->num_rows : 0; $this->id = $this->dbh->insert_id; $this->rows = $this->dbh->affected_rows; while ($iterator < $this->length) { $result[$iterator] = $data->fetch_array($fetch); $iterator++; } if (is_object($data)) { $data->free(); } break; case "MYSQL_PDO": case "SQLITE_PDO": if (!is_object($data)) { throw new DatabaseException('Invalid result data for model ' . $this->model); } switch ($this->fetch) { case 'NUM': $fetch = \PDO::FETCH_NUM; break; case 'ASSOC': $fetch = \PDO::FETCH_ASSOC; break; default: $fetch = \PDO::FETCH_BOTH; break; } try { $result = $data->fetchAll($fetch); } catch (\PDOException $pe) { $result = true; } $this->length = sizeof($result); $this->id = $this->dbh->lastInsertId(); $this->rows = $data->rowCount(); break; case "ORACLE_PDO": if (!is_object($data)) { throw new DatabaseException('Invalid result data for model ' . $this->model); } switch ($this->fetch) { case 'NUM': $fetch = \PDO::FETCH_NUM; break; case 'ASSOC': $fetch = \PDO::FETCH_ASSOC; break; default: $fetch = \PDO::FETCH_BOTH; break; } $result = $data->fetchAll($fetch); $this->length = sizeof($result); $this->rows = $data->rowCount(); try { $this->id = $this->oracleLastInsertId(); } catch (DatabaseException $de) { throw $de; } break; case "DBLIB_PDO": if (!is_object($data)) { throw new DatabaseException('Invalid result data for model ' . $this->model); } switch ($this->fetch) { case 'NUM': $fetch = \PDO::FETCH_NUM; break; case 'ASSOC': $fetch = \PDO::FETCH_ASSOC; break; default: $fetch = \PDO::FETCH_BOTH; break; } $result = $data->fetchAll($fetch); $this->length = sizeof($result); $this->rows = $data->rowCount(); try { $this->id = $this->dblibLastInsertId(); } catch (DatabaseException $de) { throw $de; } break; case "DB2": if (!is_resource($data) or @get_resource_type($data) != "DB2 Statement") { throw new DatabaseException('Invalid result data for model ' . $this->model); } $this->length = db2_num_fields($data); $this->id = db2_last_insert_id($this->dbh); $this->rows = db2_num_rows($data); switch ($this->fetch) { case 'NUM': while ($row = db2_fetch_row($data)) { array_push($result, $row); } break; case 'ASSOC': while ($row = db2_fetch_assoc($data)) { array_push($result, $row); } break; default: while ($row = db2_fetch_both($data)) { array_push($result, $row); } break; } break; case "POSTGRESQL": if (!is_resource($data) or @get_resource_type($data) != "pgsql result") { throw new DatabaseException('Invalid result data for model ' . $this->model); } $this->length = pg_num_rows($data); $this->id = pg_last_oid($data); $this->rows = pg_affected_rows($data); while ($iterator < $this->length) { switch ($this->fetch) { case 'NUM': $result[$iterator] = pg_fetch_array($data); break; case 'ASSOC': $result[$iterator] = pg_fetch_assoc($data); break; default: $result[$iterator] = pg_fetch_all($data); break; } $iterator++; } break; } return array("data" => $result, "length" => $this->length, "id" => $this->id, "affected_rows" => $this->rows); }