mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 21:27:25 +02:00
MySQL: Fix for return when using '_DUPLICATE_KEY_UPDATE'
This commit is contained in:
@@ -803,7 +803,7 @@ class e_db_mysql
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int Last insert ID or false on error
|
* @return int Last insert ID or false on error. When using '_DUPLICATE_KEY_UPDATE' return ID, true on update, 0 on no change and false on error.
|
||||||
* @param string $tableName - Name of table to access, without any language or general DB prefix
|
* @param string $tableName - Name of table to access, without any language or general DB prefix
|
||||||
* @param string/array $arg
|
* @param string/array $arg
|
||||||
* @param string $debug
|
* @param string $debug
|
||||||
@@ -819,30 +819,26 @@ class e_db_mysql
|
|||||||
$table = $this->db_IsLang($tableName);
|
$table = $this->db_IsLang($tableName);
|
||||||
$this->mySQLcurTable = $table;
|
$this->mySQLcurTable = $table;
|
||||||
$REPLACE = false; // kill any PHP notices
|
$REPLACE = false; // kill any PHP notices
|
||||||
|
$DUPEKEY_UPDATE = false;
|
||||||
|
|
||||||
if(is_array($arg))
|
if(is_array($arg))
|
||||||
{
|
{
|
||||||
if(isset($arg['WHERE'])) // use same array for update and insert.
|
if(isset($arg['WHERE'])) // use same array for update and insert.
|
||||||
{
|
{
|
||||||
unset($arg['WHERE']);
|
unset($arg['WHERE']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($arg['_REPLACE']))
|
if(isset($arg['_REPLACE']))
|
||||||
{
|
{
|
||||||
$REPLACE = TRUE;
|
$REPLACE = TRUE;
|
||||||
unset($arg['_REPLACE']);
|
unset($arg['_REPLACE']);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$REPLACE = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($arg['_DUPLICATE_KEY_UPDATE']))
|
if(isset($arg['_DUPLICATE_KEY_UPDATE']))
|
||||||
{
|
{
|
||||||
$DUPEKEY_UPDATE = true;
|
$DUPEKEY_UPDATE = true;
|
||||||
unset($arg['_DUPLICATE_KEY_UPDATE']);
|
unset($arg['_DUPLICATE_KEY_UPDATE']);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$DUPEKEY_UPDATE = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data']))
|
if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data']))
|
||||||
@@ -853,6 +849,7 @@ class e_db_mysql
|
|||||||
$arg = $_tmp;
|
$arg = $_tmp;
|
||||||
unset($_tmp);
|
unset($_tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($arg['data'])) { return false; }
|
if(!isset($arg['data'])) { return false; }
|
||||||
|
|
||||||
|
|
||||||
@@ -935,6 +932,28 @@ class e_db_mysql
|
|||||||
|
|
||||||
$this->mySQLresult = $this->db_Query($query, NULL, 'db_Insert', $debug, $log_type, $log_remark);
|
$this->mySQLresult = $this->db_Query($query, NULL, 'db_Insert', $debug, $log_type, $log_remark);
|
||||||
|
|
||||||
|
if($DUPEKEY_UPDATE === true)
|
||||||
|
{
|
||||||
|
$result = false; // ie. there was an error.
|
||||||
|
|
||||||
|
if($this->mySQLresult === 1) // insert.
|
||||||
|
{
|
||||||
|
$result = $this->lastInsertId();
|
||||||
|
}
|
||||||
|
elseif($this->mySQLresult === 2) // updated
|
||||||
|
{
|
||||||
|
$result = true;
|
||||||
|
}
|
||||||
|
elseif($this->mySQLresult === 0) // updated (no change)
|
||||||
|
{
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dbError('db_Insert');
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($this->mySQLresult)
|
if ($this->mySQLresult)
|
||||||
{
|
{
|
||||||
if(true === $REPLACE)
|
if(true === $REPLACE)
|
||||||
|
Reference in New Issue
Block a user