• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using the database driver within a library

#1
[eluser]thisischris[/eluser]
Hey guys, I'm pretty new to CG and have stumbled into my first bump.
I'm trying to use the database within a custom library.

I can only guess that it's because it's not extending the CI_Controller hence not available? What should I be doing?

I get the following error:
Fatal error: Call to a member function database() on a non-object in...

Which is:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User {
    public function check_user_avail($string)
    {
  $this->load->database();
  $query = $this->db->query("SELECT COUNT(*) FROM users WHERE username='$string'");
  if ($query->num_rows() == 0)
  {return TRUE;
  }
  else
  {return FALSE;
  }
    }
}
/* End of file User.php */


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.