Welcome Guest, Not a member yet? Register   Sign In
Multiple update in single query.
#9

[eluser]Truong Chuong DUong[/eluser]
Try to run multi query in same execute will save server cost. Only need to change a bit in file CodeIgniter\system\database\drivers\mysqli\mysqli_driver.php will make CodeIgniter support this feature:

/**
* Execute the query
*
* @param string an SQL query
* @return mixed
*/
protected function _execute($sql)
{
/*
Remove this line
return @$this->conn_id->query($this->_prep_query($sql));
*/

$sql = $this->_prep_query($sql);
$result = NULL;

/* execute multi query */
if (@$this->conn_id->multi_query($sql))
{
do
{
if ($result)
@$result->free();

$result = $this->conn_id->store_result()
}
while ($this->conn_id->next_result());
}

if ($result === FALSE)
$result = 1;

/* close connection */
return $result;//Only return last result

}



If you see @mysqli_query($this->conn_id, $sql); instead of @$this->conn_id->query($this->_prep_query($sql)) (old version)
Please use these code:


/**
* Execute the query
*
* @param string an SQL query
* @return mixed
*/
protected function _execute($sql)
{
/*
Remove these line
$result = @mysqli_query($this->conn_id, $sql);
return $result;
*/


$sql = $this->_prep_query($sql);
$result = NULL;

/* execute multi query */
if (@mysqli_multi_query($this->conn_id, $sql))
{
do
{
if ($result)
@mysqli_free_result($result);

$result = @mysqli_store_result($this->conn_id);
}
while (mysqli_next_result($this->conn_id));
}

if ($result === FALSE)
$result = 1;

return $result;//Only return last result

}


Messages In This Thread
Multiple update in single query. - by El Forum - 09-22-2010, 02:18 AM
Multiple update in single query. - by El Forum - 09-22-2010, 04:41 AM
Multiple update in single query. - by El Forum - 09-22-2010, 04:49 AM
Multiple update in single query. - by El Forum - 09-22-2010, 04:52 AM
Multiple update in single query. - by El Forum - 09-22-2010, 05:08 AM
Multiple update in single query. - by El Forum - 09-22-2010, 05:29 AM
Multiple update in single query. - by El Forum - 09-22-2010, 05:35 AM
Multiple update in single query. - by El Forum - 09-22-2010, 03:05 PM
Multiple update in single query. - by El Forum - 04-13-2012, 02:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB