I am new to programming and would like to connect to a ms-access (accdb) database using a PDO class. Environement: PHP (5.5.11) / XAMPP / Windows 7 pro. PDO driver for ODBC (win32) is enabled.
class db{
protected $dbName = "C:\xampp\htdocs\BillboardsManagement\Core\config\Billboards.accdb";
protected $Uid="";
protected $Upass="";
protected $conn;
public function __construct() {
try{
$this -> conn = new PDO('odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=$this->$dbName;Uid=$this->$Uid;Pwd=$this->$Upass');
} catch (Exception $e) {
echo "\n $e-> getMessage()\n";
}
}
}
When I try to instantiate the class, I get the following error:
exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' in C:\xampp\htdocs\BillboardsManagement\Core\config\config.php:13 Stack trace: #0 C:\xampp\htdocs\BillboardsManagement\Core\config\config.php(13): PDO->__construct('odbc:DRIVER={Mi...') #1 C:\xampp\htdocs\BillboardsManagement\Views\selectBB.php(3): db->__construct() #2 {main}-> getMessage() Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\BillboardsManagement\Core\classes\bbClasses.php on line 11
Thanks in advance for your help.
Updates: I understand that a similar question was answered before. But I am in a learning process. The answer to the previous post was to use adodb instead of PDO ( for reasons I totally agree with) , but I am still curious about what went wrong in my particular situation. I still cannot determine whether my code was faulty or it was some odbc driver or configuration issue.