CodeIgniter Forums

Full Version: Database loading problems
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Hi,

I'm using CI on a XAMPP-system on Windows XP. I've installed CI some days ago and tried today to connect to my MySQL-database. But there is coming this message:
Code:
Fatal error: Call to undefined method CI_DB_mysql_driver::_assign_libraries() in C:\Programme\xampp\htdocs\codeigniter\system\libraries\Loader.php on line 921
I think, that I didn't make something wrong, because I copied the Code right from the user-guide. Also I didn't change something in that core-files.

Can someone help me?

El Forum

[eluser]obiron2[/eluser]
Without stating the obvious, you have started the Apache and MySQL services havn't you?

I would be guessing that the basepath configuration is wrong.

Where is the CI directory in relation to the XAMPP directory?

El Forum

[eluser]Unknown[/eluser]
services are started, a normal page works.
I tried it now over auto-loading the database, this works. But its unnecessary, because I need the database for nearly no pages...

El Forum

[eluser]LeonardoRaygoza[/eluser]
Im having the same problem, I set on the database.php the credentials to mY localhost, Im trying to work on mysql, I followed the user-guide.

I created a new model, then the function.

<?php

class Blogmodel extends Model {

function Blogmodel
{
parent::Model();
$this->load->database();
}

function get_entries()
{
$query = $this->db->query('Select * from mytable');
}

}
?>


then I'm calling the model from controller.

<?php

class Blog extends Controller{

function Blog()
{
parent::Controller();
}

function index()
{
$this->load->model('blog_model');
$data['query'] = $this->blog_model->get_entries();

$this->load->view('blog_view', $data);
}
}

?>


this is my view code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Leo's Blog&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<h1>This is my blog!</h1>

&lt;?php
foreach($query->result() as $row)
{
echo $row->id_usuario;
echo $row->nombre;
echo $row->usuario;
echo $row->password;
echo $row->email;
}


?&gt;

&lt;/body&gt;
&lt;/html&gt;

El Forum

[eluser]flaky[/eluser]
fix
Code:
function get_entries()
      {
        $query = $this->db->query(‘Select * from mytable’);
      }
to
Code:
function get_entries()
      {
        $query = $this->db->query(‘Select * from mytable’);
        return $query->result_array();
      }

El Forum

[eluser]CI_avatar[/eluser]
please post your database configuration.

Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "database_name";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

El Forum

[eluser]LeonardoRaygoza[/eluser]
this is my database configuration:

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

I fixed the model as Flaky said and now the model can be loaded, but when I'm trying to show the entries on the view I get the error: Fatal error: Call to a member function result_array() on a non-object in C:\wamp\www\mvc\system\application\views\blog_view.php on line 13

my view code is:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” /&gt;
&lt;title&gt;Leo’s Blog&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<h1>This is my blog!</h1>

&lt;?php
foreach($query->result_array() as $row) <- this is my line 13
{
echo $row['id_usuario'];
echo $row['nombre'];
echo $row['usuario'];
echo $row['password'];
}
?&gt;

&lt;/body&gt;
&lt;/html&gt;

My model fixed:

&lt;?php

class Blog_model extends Model {

function Blog_model()
{
parent::Model();
$this->load->database();
}

function get_entries()
{
$query = $this->db->query('Select * from user');
return $query->result_array();
}

}
?&gt;

and my controller:

&lt;?php

class Blog extends Controller{

function Blog()
{
parent::Controller();
}

function index()
{
$this->load->model('blog_model');
$data['query'] = $this->blog_model->get_entries();
$this->load->view('blog_view', $data);
}
}

?&gt;

I really don't understand why Im getting the error, maybe Im missing something...

thanks for help Smile

El Forum

[eluser]WebsiteDuck[/eluser]
In your view do
Code:
foreach($query as $row)
  {
    echo $row['id_usuario'];
    echo $row['nombre'];
    echo $row['usuario'];
    echo $row['password'];
  }

Because you are returning an array from the model, not an object containing an array

El Forum

[eluser]LeonardoRaygoza[/eluser]
yeah!!! it works!!! great WebsiteDuck, thanks everybody for help me Wink