Welcome Guest, Not a member yet? Register   Sign In
database load issue
#1

[eluser]Unknown[/eluser]
I've seen several threads on this question, but there does not seem to be a consistent fix (any many of the questions are terribly written). It's also unclear if the problem is always user-build specific. Like many of the others running into this problem on the forums, I'm new to Code Igniter, but I'm loving the idea of a MVC framework. I'm running this locally on a MAMP build with PHP 5.3.5, mysql 5.5.9 and CodeIgniter 2.0.2. In the following I try to be as thorough as possible to narrow down where the error is happening.

I'm getting a blank page when I load a database connection, but otherwise my code works fine. Here is a simplified version of my code:
BlogTest.php
Code:
<?php
class BlogTest extends CI_Controller {
  public function index() {
    $this->load->model('Webtest_model', 'webdb');
    $html_input['base_subjects'] = $this->webdb->get_root_subjects();
    $html_input['title'] = "my title";
    $html_input['realhead'] = "This is code generated!";
    $this->load->view('testview.html', $html_input);
  }
}
?>
testview.html
Code:
<html>
<head>
  <title><?php echo $title;?></title>
</head>
<body>
  <h1>&lt;?php echo $realhead; ?&gt;</h1>
  &lt;?php echo $base_subjects; ?&gt;
&lt;/body&gt;
&lt;/html&gt;
webtest_model.php
Code:
&lt;?php
class Webtest_model extends CI_Model {
  function __construct(){
    // Calling Model constructor
    parent::__construct();
  }

  function get_root_subjects() {
    $this->load->database();
    //$query = $this->db->query('SELECT * FROM subject_def');
    //$query = $this->db->get('entries', 5);
    //return $query->result();
    return "coming from model";
  }
}
?&gt;
When I call the above code, I get exactly what one would expect--a page that says "This is code generated!" with a line under it that says "coming from model." Unfortunately if I un-comment the "$this->load->database();" line, the site I get returned is blank. I've tested loading libraries (the 'table' library, among others, loads fine). I have also found that if I try to load the database library through the autoload.php file as $autoload('libraries') = array('database');, I get the same behavior (blank site).

My database.php file has my credentials and dbdriver as mysql. To be even more thorough, I tried taking the ['autoinit'] = FALSE. If I understand the config correctly, that means when I load the database library it does not try to connect automatically, so I think that means it's not my credentials that is giving me a blank page. I can connect to it just fine in mysql via my terminal and use the database I am trying to connect to.

I do not have leading or trailing whitespace after my php tags (as one can tell since my html generally loads without my database call). I'm getting into the model just fine, since the "coming from model" text comes up. I do not get any error in my error log and my error_reporting is set to E_ALL in my config.php file.

Any other thoughts as to what I'm doing wrong here?

aTdHvAaNnKcSe
#2

[eluser]CodeIgniteMe[/eluser]
Have you tried setting the error_reporting function in your index.php file?
#3

[eluser]InsiteFX[/eluser]
Try Adding the doctype <!DOCTYPE html>

InsiteFX
#4

[eluser]7thChosen[/eluser]
having the same problem, using CI 2.0.2, mysql 5.1 and PHP 5, getting a blank page whenever i use the line "$this->load->database();" in the controller (blog_view.php), or when i use the line "$autoload['libraries'] = array('database');" in the autoload.php file...
#5

[eluser]danmontgomery[/eluser]
Check apache error log. Do you have the appropriate php module for whatever db driver you're using?
#6

[eluser]7thChosen[/eluser]
thank you for suggesting checking the apache logs, it was in fact a wrong path in the httpd.conf file... grrr... awesome

i was getting this error in the apache error log file:

PHP Warning: PHP Startup: Unable to load dynamic library 'c:\\PHP\\ext\\php_mysql.dll' - No se puede encontrar el m\xf3dulo especificado.\r\n in Unknown on line 0

soo i fix the path in the httpd.conf file, at the end of the section where the "LoadModule" sentences are just add this line:

LoadModule php5_module c:/php/php5apache2_2.dll

or u can copy the file into the apache/modules directory and use:

LoadModule php5_module moldules/php5apache2_2.dll

soo now i can connect to my MySQL database using:

$autoload['libraries'] = array('database'); in the autoload.php file of codeigniter

or the $this->load->database(); sentence used in my controller...

hope this help somebody else... here are some helpfull links i found that helped me fix this problem:

http://www.webcheatsheet.com/PHP/install...acheconfig
http://justcheckingonall.wordpress.com/2...n-windows/

thank you again, and happy coding... peace out




Theme © iAndrew 2016 - Forum software by © MyBB