CodeIgniter Forums
Easy migration from mysql syntax to CI syntax. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Easy migration from mysql syntax to CI syntax. (/showthread.php?tid=41669)



Easy migration from mysql syntax to CI syntax. - El Forum - 05-13-2011

[eluser]debow[/eluser]
I'm trying to covert this...

Code:
$sql = "UPDATE eresults set eventrank=NULL and eventscore=NULL";
    $res = sqlQuery($sql);
    return 99;

To this.. but below isn't working.
Code:
$this->db->update('eresults');
$this->db->set('eventrank','NULL');
$this->db->set('eventscore','NULL');
$this->db->where('event','100m');
$return $this->db->affected_rows();

Any suggestions. Thanks


Easy migration from mysql syntax to CI syntax. - El Forum - 05-13-2011

[eluser]TWP Marketing[/eluser]
Just offhand, change the order of your setup:
Code:
$this->db->set('eventrank','NULL');
$this->db->set('eventscore','NULL');
$this->db->where('event','100m');
$this->db->update('eresults');
$return $this->db->affected_rows();



Easy migration from mysql syntax to CI syntax. - El Forum - 05-13-2011

[eluser]CroNiX[/eluser]
should probably be NULL, not "NULL" since its not a string. And yes, the "update" or "insert" is what is actually triggering the query, so it should go very last so that the other operations get triggered.


Easy migration from mysql syntax to CI syntax. - El Forum - 05-13-2011

[eluser]debow[/eluser]
That worked, thank you.