![]() |
Empty database output within CI - 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: Empty database output within CI (/showthread.php?tid=30263) |
Empty database output within CI - El Forum - 05-08-2010 [eluser]den-javamaniac[/eluser] Hi. I'm building a simple app (using video tutorials and reference documentation) and trying to test DB result output. But unfortunately all I'm getting is an array of size 0. Here's the controller code excerpt: Code: $data['query'] = $this->db->query('SELECT role_id, role_privilege FROM role'); Code: <?php Code: 0 Empty database output within CI - El Forum - 05-08-2010 [eluser]WanWizard[/eluser] What is $query in this example? Do you mean $data['query'], which holds the result of the query? Empty database output within CI - El Forum - 05-08-2010 [eluser]den-javamaniac[/eluser] Yes, that's correct. That's how it's done in a video tutorial. NOTE:This issue is also discussed here. Empty database output within CI - El Forum - 05-08-2010 [eluser]Aken[/eluser] var_dump your query variable inside the view, to see what exactly is getting passed to it. If it's NULL or something similar, then there's an error with your actual query command somewhere. Did you load the DB library? Did you add your database credentials to the DB config file? etc etc. Empty database output within CI - El Forum - 05-08-2010 [eluser]WanWizard[/eluser] [quote author="den-javamaniac" date="1273367365"]Yes, that's correct. That's how it's done in a video tutorial.[/quote] I mean that in your example you fetch the query result in the variable $data['query'], then you continue with using the variable $query, which is never assigned a value. I assume this is an error in the tutorial?! Empty database output within CI - El Forum - 05-08-2010 [eluser]den-javamaniac[/eluser] I presume that your assumption is incorrect. If I use $data['query'], I get a "Undefined variable: data" error. Besides, if using Code: $data['title'] = "Welcome to CodeIgniter"; Code: <?php foreach ($msg as $string): ?> Empty database output within CI - El Forum - 05-08-2010 [eluser]den-javamaniac[/eluser] Well, this here problem is basically not a CI related one, but strange thing is that CI couldn't track this error. Here's what was going on: While installing php I haven't specified --with-mysql-socket parameter and it looks like php tried to use a /tmp/mysql.sock (default one) which obviously was not specified in my.cnf. So CI tried to bind to a nonexistent socket. Changing mysql params in a php.ini solved the problem. |