Welcome Guest, Not a member yet? Register   Sign In
need help using pdo in CI
#1

[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;
}
}




Theme © iAndrew 2016 - Forum software by © MyBB