CodeIgniter Forums
MySQL not working - 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 not working (/showthread.php?tid=34497)

Pages: 1 2


MySQL not working - El Forum - 10-01-2010

[eluser]klompie[/eluser]
Have searched for this en found others with the same sort of problems, but cant solve this.

when i use $autoload['libraries'] = array('database'); nothing will load. every page i open stays white. (no source too)

this is my loaded controller:
Code:
<?php

class Klant extends Controller {

    function Klant()
    {
        parent::Controller();
    }
  
    function index()
    {
        echo 'Hello World!<br>';
        mysql_connect("localhost","crm_user","******") or die(mysql_error());
        mysql_selectdb("dtd_crm") or die(mysql_error());
        echo 'Connected!';
    }
}

/* End of file klant.php */
/* Location: ./application/controllers/klant.php */

when i disable autoloading of database it echo's "Hello World! Connected!" so this way it is working.

I tried setting pconnect to false but this did not solve it.

So how to solve this. Sad


MySQL not working - El Forum - 10-01-2010

[eluser]jmadsen[/eluser]
That "white page" probably has an error message written in magic ink; go to:

htdocs/index.php and set "error_reporting(E_ALL);"

It should give you a message to help get you started, or at least to report to us so we can explain it.


MySQL not working - El Forum - 10-01-2010

[eluser]klompie[/eluser]
Error reporting is set to E_ALL. (By default CI runs with error reporting set to ALL)


MySQL not working - El Forum - 10-01-2010

[eluser]jmadsen[/eluser]
have you tried using the CI db class instead of php's functions? Does that work?

also, is your config/database.php file set up correctly?


I'm not really sure what the issue would be, but most people have no trouble, so probably just a config, etc. not set up correctly


MySQL not working - El Forum - 10-01-2010

[eluser]klompie[/eluser]
How do you mean?
Using php functions it is working.
using $autoload[‘libraries’] = array(‘database’); it is not working


MySQL not working - El Forum - 10-01-2010

[eluser]jmadsen[/eluser]
instead of

Code:
mysql_connect("localhost","crm_user","******") or die(mysql_error());
mysql_selectdb("dtd_crm") or die(mysql_error());


use:

Code:
$this->db->query('YOUR QUERY HERE');



MySQL not working - El Forum - 10-01-2010

[eluser]klompie[/eluser]
With autoload enabled it gives me a white screen.
With autolood disable is gives me Message: Undefined property: Klant::$db
(as expected)


MySQL not working - El Forum - 10-01-2010

[eluser]jmadsen[/eluser]
is this with the method I suggested? ($this->db->query('YOUR QUERY HERE'); )

also, what does your database.php file look like?


Please give us ALL the information you can.


MySQL not working - El Forum - 10-01-2010

[eluser]klompie[/eluser]
This is my database.php:
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -----------

...

| The $active_record variables lets you determine whether or not to load
| the active record class
*/

$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "crm_user";
$db['default']['password'] = "****************";
$db['default']['database'] = "dtd_crm";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";


/* End of file database.php */
/* Location: ./application/config/database.php */

this is my controller:
Code:
&lt;?php

class Klant extends Controller {

    function Klant()
    {
        parent::Controller();
    }
  
    function index()
    {
        echo 'Hello World!<br>';
        $this->db->query('SELECT * FROM klanten');
        echo 'Connected!';
    }
}

/* End of file klant.php */
/* Location: ./application/controllers/klant.php */

this is my autoload:
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$autoload['libraries'] = array('database');

$autoload['helper'] = array('url');

$autoload['plugin'] = array();

$autoload['config'] = array();

$autoload['language'] = array();

$autoload['model'] = array();



/* End of file autoload.php */
/* Location: ./system/application/config/autoload.php */



And this gives me... nothing (a white screen)


MySQL not working - El Forum - 10-01-2010

[eluser]techgnome[/eluser]
Are you sure mySQL is up and running? There has been more than once when I've forgotten to hit the Start button to spin up mySQL.

-tg