![]() |
Not able to run a query - 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: Not able to run a query (/showthread.php?tid=31657) |
Not able to run a query - El Forum - 06-27-2010 [eluser]shinokada[/eluser] I am creating a cronjob.php I have the following controller and model. Code: class Mycronjob extends Controller { I have a demodatabse.txt with the followings. Code: INSERT INTO `be_acl_groups` (`id`, `lft`, `rgt`, `name`, `link`) VALUES I have a problem with function insert_data(). It gives an error "Query was empty" If I change to this, then it works. Code: Change this I tried this one, but it does not work either. Code: $inserts = read_file('assets/sql/demodatabase.txt'); I am hoping someone can give me advices how I can fix this. Thanks in advance. Not able to run a query - El Forum - 06-27-2010 [eluser]pickupman[/eluser] I would make sure you have the correct path for read_file(). What happens if you echo $inserts? Not able to run a query - El Forum - 06-27-2010 [eluser]shinokada[/eluser] path is ok. When I output the data (without query)in a view, it shows all the content. Not able to run a query - El Forum - 06-28-2010 [eluser]pickupman[/eluser] At first glance, everything looked correct, and them I happened to remember you have trim the trailing ; at the end. explode() will create a empty array at the end of $contents. You can use this: Code: $contents = explode(';', rtrim($inserts,';')); Explode on your string data will create an array like [0] => Query 1 [1] => Query 2 [2] => NULL That is why you are getting an empty query. |