CodeIgniter Forums
need help using pdo in 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: need help using pdo in CI (/showthread.php?tid=51947)



need help using pdo in CI - El Forum - 05-24-2012

[eluser]Abel A.[/eluser]
I'm trying to run a query in a library I'm making. When I load the following library from a controller I get a php 500 error. The 500 error is caused by the prepare statement, I'm certain of that.

Note: I run my sessions from mysql using pdo, so the config.php file is fine. I think I'm just calling the prepare statement wrong. Any ideas?
Code:
class Authentication {

public $userinfo = array();
public $CI;

public function __construct()
{
  $this->CI =& get_instance();
  $this->CI->load->library('session');

  $this->userinfo = $this->CI->session->all_userdata();
  
  if ($this->CI->input->post('username')) $this->login();
}

public function login()
{
  $this->CI->load->database();
  $username = $this->CI->input->post('username');
  
  $stmt = $this->CI->db->prepare("SELECT * FROM pos_user
          WHERE username = :username
          LIMIT 1");
  //$stmt->execute(array(':username' => $username));
  //$user_data = $statement->fetchObject();
  //echo $user_data->userid;
  exit;
}
}