Im attempting to rewrite my code with PDO. It is hosted on a commercial unix shared hosting (php 5,4, mysql pdo driver is available).
The code:
class User {
//the basic properties of the User
public $uid; // = login
public $password; // password
//db creds
const server = 'db14.somedomain.com';
const db = "db_name";
const mysql_login = "mysql_login";
const mysql_pass = "somepass";
// prepared statements
//main constructor
public function __construct ($uid, $password){
$this->uid = $uid;
$this->password = md5($password);
}
public function login (){
// defining the constants below is redundant, i know.
define ("DB_DRIVER", "mysql");
define ("DB_CHARSET", "UTF8");
define ("DB_HOST", "$this->server");
define ("DB_USER", "$this->mysql_login");
define ("DB_PASS", "$this->mysql_pass");
define ("DB_NAME", "$this->mysql_login");
try {
$conn = new PDO("dbname=".DB_NAME.";mysql:host=".DB_HOST, DB_USER, DB_PASS);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare ("SELECT uid, fname, lname, dob, suspended, language FROM users WHERE users.'uid'=:uid AND users.'password'=:password LIMIT 1");
$stmt->bindParam("uid", $this->uid);
$stmt->bindParam("password", $this->password);
$stmt->execute();
$count=$stmt->rowCount();
$userRow = $stmt->fetch(PDO::FETCH_ASSOC);
$conn = null;
if($count)
{
$_SESSION['uid']=$data->uid; // Storing user session value
return true;
}
else
{
return false;
}
}
catch(PDOException $e) {
echo 'error: '. $e->getMessage() ;
}
}
}
$user = new User ($_POST['login'], $_POST['password']);
$login_check = $user->login();
The script returns error "could not find driver"
Could anyone please look into this?