mirror of
https://github.com/e107inc/e107.git
synced 2025-08-02 12:48:26 +02:00
Expanded use of passing field types with db_Insert and db_Update
This commit is contained in:
@@ -12,8 +12,8 @@
|
|||||||
| GNU General Public License (http://gnu.org).
|
| GNU General Public License (http://gnu.org).
|
||||||
|
|
|
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
|
||||||
| $Revision: 1.26 $
|
| $Revision: 1.27 $
|
||||||
| $Date: 2008-11-26 23:34:35 $
|
| $Date: 2008-11-27 20:13:58 $
|
||||||
| $Author: mcfly_e107 $
|
| $Author: mcfly_e107 $
|
||||||
|
|
|
|
||||||
+----------------------------------------------------------------------------+
|
+----------------------------------------------------------------------------+
|
||||||
@@ -30,7 +30,7 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
|
|||||||
* MySQL Abstraction class
|
* MySQL Abstraction class
|
||||||
*
|
*
|
||||||
* @package e107
|
* @package e107
|
||||||
* @version $Revision: 1.26 $
|
* @version $Revision: 1.27 $
|
||||||
* @author $Author: mcfly_e107 $
|
* @author $Author: mcfly_e107 $
|
||||||
*/
|
*/
|
||||||
class db {
|
class db {
|
||||||
@@ -311,7 +311,13 @@ class db {
|
|||||||
if(is_array($arg))
|
if(is_array($arg))
|
||||||
{
|
{
|
||||||
$keyList= "`".implode("`,`", array_keys($arg))."`";
|
$keyList= "`".implode("`,`", array_keys($arg))."`";
|
||||||
$valList= "'".implode("','", $arg)."'";
|
$tmp = array();
|
||||||
|
foreach($arg as $fv)
|
||||||
|
{
|
||||||
|
$tmp[] = $this->_getFieldValue($fv);
|
||||||
|
}
|
||||||
|
$valList= implode(', ', $tmp);
|
||||||
|
unset($tmp);
|
||||||
$query = "INSERT INTO `".$this->mySQLPrefix."{$table}` ({$keyList}) VALUES ({$valList})";
|
$query = "INSERT INTO `".$this->mySQLPrefix."{$table}` ({$keyList}) VALUES ({$valList})";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -370,30 +376,16 @@ class db {
|
|||||||
unset($arg['WHERE']);
|
unset($arg['WHERE']);
|
||||||
foreach ($arg as $fn => $fv)
|
foreach ($arg as $fn => $fv)
|
||||||
{
|
{
|
||||||
$new_data .= ($new_data) ? ", " : "";
|
$new_data .= ($new_data ? ', ' : '');
|
||||||
if(!is_array($fv)) { $fv = array('string', $fv); }
|
$new_data .= "`{$fn}`=".$this->_getFieldValue($fv);
|
||||||
switch ($fv[0])
|
|
||||||
{
|
|
||||||
case 'int':
|
|
||||||
$new_data .= "`{$fn}`=".(int)$fv[1];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'cmd':
|
|
||||||
$new_data .= "`{$fn}`={$fv[1]}";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$new_data .= "`{$fn}`='{$fv[1]}'";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
$arg = $new_data .' WHERE '. $the_where;
|
||||||
$arg = $new_data ." WHERE ". $the_where;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.$this->mySQLPrefix.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark))
|
if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.$this->mySQLPrefix.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark))
|
||||||
{
|
{
|
||||||
$result = mysql_affected_rows($this->mySQLaccess);
|
$result = mysql_affected_rows($this->mySQLaccess);
|
||||||
if ($result == -1) return FALSE; // Error return from mysql_affected_rows
|
if ($result == -1) { return false; } // Error return from mysql_affected_rows
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -403,6 +395,41 @@ class db {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
* @param string|array $fieldValue
|
||||||
|
* @desc Return new field value in proper format<br />
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _getFieldValue($fieldValue)
|
||||||
|
{
|
||||||
|
if(!is_array($fieldValue))
|
||||||
|
{
|
||||||
|
return "'{$fieldValue}'";
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($fieldValue[0])
|
||||||
|
{
|
||||||
|
case 'int':
|
||||||
|
return (int)$fieldValue[1];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'cmd':
|
||||||
|
return $fieldValue[1];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'todb':
|
||||||
|
$e107 = e107::getInstance();
|
||||||
|
return "'".$e107->tp->toDB($fieldValue[1])."'";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "'{$fieldValue[1]}'";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Similar to db_Update(), but splits the variables and the 'WHERE' clause.
|
/* Similar to db_Update(), but splits the variables and the 'WHERE' clause.
|
||||||
$vars may be an array (fieldname=>newvalue) of fields to be updated, or a simple list.
|
$vars may be an array (fieldname=>newvalue) of fields to be updated, or a simple list.
|
||||||
$arg is usually a 'WHERE' clause
|
$arg is usually a 'WHERE' clause
|
||||||
|
Reference in New Issue
Block a user