MYSQL problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: MYSQL problem (/showthread.php?tid=56021) |
MYSQL problem - El Forum - 11-21-2012 [eluser]Speedy`[/eluser] Hi there, I have one little problem here. I am trying to use database functions from codeigniter but it seems there is a problem with the functions or my code. I have this $this->db->where('date',$data['date']); $query = $this->db->get('exchangerates'); with $this->db->last_query() it generates this SELECT * FROM (`exchangerates`) WHERE `date` = '2012-11-21' the $query->num_rows() returns 0 even if in the database are records with this date. same problem at insert. $exchange = array( 'date' => $data['date'], 'usd' => $data['usd'], 'eur' => $data['eur'] ); $this->db->insert('exchangerates',$exchange); echo $this->db->last_query(); generates this INSERT INTO `exchangerates` (`date`, `usd`, `eur`) VALUES ('2012-11-21', '3.5474', '4.5339') When I run this sql from phpmyadmin it is all OK. From codeigniter the date is inserted as '0000-00-00' Can anyone tell me how to solve this problem? I have tried to convert string to date from human to unix, to call date() but nothing happened. Thanks MYSQL problem - El Forum - 11-21-2012 [eluser]jprateragg[/eluser] What version of CI are you using? MYSQL problem - El Forum - 11-21-2012 [eluser]InsiteFX[/eluser] Try: Code: 1) If that doe's not work try using this: Code: $this->db->where('date =', $this->data['date']); MYSQL problem - El Forum - 11-22-2012 [eluser]Speedy`[/eluser] [quote author="jprateragg" date="1353547507"]What version of CI are you using?[/quote] 2.1.3 I-ll try the methods and come back withan answer MYSQL problem - El Forum - 11-22-2012 [eluser]Speedy`[/eluser] [quote author="InsiteFX" date="1353550555"]Try: Code: 1) If that doe's not work try using this: Code: $this->db->where('date =', $this->data['date']); It seems that is not working Undefined property: Site::$2012-11-21 The sql returns 0 rows from codeigniter and phpmyadmin returns 1. MYSQL problem - El Forum - 11-22-2012 [eluser]JunlieF[/eluser] pls. corrent me about this code... $sql = "SELECT * FROM deparments, prints WHERE 'id{$dept}' AND 'date_printed BETWEEN '{$from}' AND '{$to}'"; MYSQL problem - El Forum - 11-22-2012 [eluser]Speedy`[/eluser] [quote author="JunlieF" date="1353582092"] pls. corrent me about this code... $sql = "SELECT * FROM deparments, prints WHERE 'id{$dept}' AND 'date_printed BETWEEN '{$from}' AND '{$to}'";[/quote] Where clause WHERE column_name operator value I'm seing just the value not the column. Operators can be =.!=, <, >.... MYSQL problem - El Forum - 11-24-2012 [eluser]Speedy`[/eluser] nobody knows where the problem with the date is? MYSQL problem - El Forum - 11-24-2012 [eluser]kostyak[/eluser] Hi Speedy! Try to use different date format from which you have being used. I think that it would be better to use standart month/date/year format instead of year-month-day. Also I had situation with mssql database. When I use smaldatetime - I received the same problem. When I swichen to datetime - all is ok. Try it. It seems that problem not in CI, which you use. |