Multiple update in single query. |
[eluser]Arun Joshi[/eluser]
I have to update multiple rows of my photos table. I have a dynamic built query like this. Code: $query = " Any reason there for this? Thanks Arun
[eluser]sunny.by[/eluser]
[quote author="Arun Joshi" date="1285161527"]I have to update multiple rows of my photos table. I have a dynamic built query like this. Code: $query = " Any reason there for this? Thanks Arun[/quote] Hello, Arun. I think error in next: For execute your query CI in file mysql_driver.php use next function: Code: /** PS: sorry for my english
[eluser]sunny.by[/eluser]
@arun Code: $query = "UPDATE photos SET description='des one' WHERE photo_id='4'";
[eluser]Arun Joshi[/eluser]
Ok, I tried to avoid multiple db access. Thats why I created one single query. Anyway thanks for your time...
[eluser]sunny.by[/eluser]
Look http://php.net/manual/en/function.mysql-query.php Quote:mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.
[eluser]cahva[/eluser]
Even phpmyadmin will parse your sql and execute those line by line. Smart thing IMO is to build an array and iterate it and use AR's update. Something like this: Code: $arr = array( If you have to do very large sets and you're running out of steam, then you should run large queries thru shell using php's exec(or passthru etc.) function and execute your sql there.
[eluser]RedIgniter[/eluser]
I think this link will help you. http://ellislab.com/codeigniter/user-gui...tml#update - Greg
[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 } |
Welcome Guest, Not a member yet? Register Sign In |