mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Add getAffectedRows() and getInsertID() to DB classes
쿼리 실행 후 affected rows, last insert ID 값을 받아올 수 있도록 DB 클래스에 관련 메소드를 추가함
This commit is contained in:
parent
8ef0d05ecb
commit
fa2b2914f2
5 changed files with 106 additions and 9 deletions
|
|
@ -1213,6 +1213,23 @@ class DB
|
|||
return $dbParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of rows affected by the last query
|
||||
* @return int
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID generated in the last query
|
||||
* @return int
|
||||
*/
|
||||
public function getInsertID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* End of file DB.class.php */
|
||||
/* Location: ./classes/db/DB.class.php */
|
||||
|
|
|
|||
|
|
@ -1117,6 +1117,26 @@ class DBCubrid extends DB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of rows affected by the last query
|
||||
* @return int
|
||||
*/
|
||||
function getAffectedRows()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
return cubrid_affected_rows($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID generated in the last query
|
||||
* @return int
|
||||
*/
|
||||
function getInsertID()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
return cubrid_insert_id($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* If have a error, return error object
|
||||
* @param BaseObject $queryObject
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ class DBMssql extends DB
|
|||
'date' => 'nvarchar(14)',
|
||||
'float' => 'float',
|
||||
);
|
||||
|
||||
/**
|
||||
* Last statement executed
|
||||
*/
|
||||
var $last_stmt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
|
@ -242,6 +247,7 @@ class DBMssql extends DB
|
|||
$this->setError(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
$this->last_stmt = $stmt;
|
||||
$this->param = array();
|
||||
|
||||
return $stmt;
|
||||
|
|
@ -988,6 +994,27 @@ class DBMssql extends DB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of rows affected by the last query
|
||||
* @return int
|
||||
*/
|
||||
function getAffectedRows()
|
||||
{
|
||||
$stmt = $this->last_stmt;
|
||||
return $stmt ? sqlsrv_rows_affected($stmt) : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID generated in the last query
|
||||
* @return int
|
||||
*/
|
||||
function getInsertID()
|
||||
{
|
||||
$result = $this->_query('SELECT @@IDENTITY as id');
|
||||
$output = $this->_fetch($result);
|
||||
return $output->id ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DBParser
|
||||
* @param boolean $force
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ class DBMysql extends DB
|
|||
'float' => 'float',
|
||||
);
|
||||
|
||||
/**
|
||||
* Last statement executed
|
||||
*/
|
||||
var $last_stmt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @return void
|
||||
|
|
@ -177,6 +182,7 @@ class DBMysql extends DB
|
|||
$this->setError(mysql_errno($connection), mysql_error($connection));
|
||||
}
|
||||
// Return result
|
||||
$this->last_stmt = $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
@ -228,7 +234,7 @@ class DBMysql extends DB
|
|||
{
|
||||
$query = sprintf("insert into `%ssequence` (seq) values ('0')", $this->prefix);
|
||||
$this->_query($query);
|
||||
$sequence = $this->db_insert_id();
|
||||
$sequence = $this->getInsertID();
|
||||
if($sequence % 10000 == 0)
|
||||
{
|
||||
$query = sprintf("delete from `%ssequence` where seq < %d", $this->prefix, $sequence);
|
||||
|
|
@ -800,16 +806,33 @@ class DBMysql extends DB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of rows affected by the last query
|
||||
* @return int
|
||||
*/
|
||||
function getAffectedRows()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
return mysql_affected_rows($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID generated in the last query
|
||||
* Return next sequence from sequence table
|
||||
* This method use only mysql
|
||||
* @return int
|
||||
*/
|
||||
function getInsertID()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
return mysql_insert_id($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return int
|
||||
*/
|
||||
function db_insert_id()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
return mysql_insert_id($connection);
|
||||
return $this->getInsertID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ class DBMysqli extends DBMysql
|
|||
}
|
||||
|
||||
// Return stmt for other processing - like retrieving resultset (_fetch)
|
||||
$this->last_stmt = $stmt;
|
||||
return $stmt;
|
||||
}
|
||||
}
|
||||
|
|
@ -135,6 +136,7 @@ class DBMysqli extends DBMysql
|
|||
$this->setError(mysqli_errno($connection), $error);
|
||||
}
|
||||
// Return result
|
||||
$this->last_stmt = $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
@ -373,12 +375,20 @@ class DBMysqli extends DBMysql
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the ID generated in the last query
|
||||
* Return next sequence from sequence table
|
||||
* This method use only mysql
|
||||
* Get the number of rows affected by the last query
|
||||
* @return int
|
||||
*/
|
||||
function db_insert_id()
|
||||
function getAffectedRows()
|
||||
{
|
||||
$stmt = $this->last_stmt;
|
||||
return $stmt ? $stmt->affected_rows : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID generated in the last query
|
||||
* @return int
|
||||
*/
|
||||
function getInsertID()
|
||||
{
|
||||
$connection = $this->_getConnection('master');
|
||||
return mysqli_insert_id($connection);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue