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
After lots and lots of reading, I discovered I was using the wrong version of the Microsoft Access Database Engine: The 64-bit version doesn't have the 32-bit driver for *.accdb format.
Thanks again for your enlightening support.
You provide the connenction details in this string:
'odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=$this->$dbName;Uid=$this->$Uid;Pwd=$this->$Upass'
If we check how strings work in PHP we can read this about our single-quoted string:
Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.
So PHP will try to open a file called $this->$dbName
, literally. So, to begin with, you possibly want one of these syntaxes instead:
"File name $foo blah"
'File name ' . $foo . ' blah'
Now, you want to read the file name from an object property:
protected $dbName = "C:\xampp\htdocs\BillboardsManagement\Core\config\Billboards.accdb";
The manual explains that the syntax is:
$this->dbName
However, you have this:
$this->$dbName
Once you fix this, it's always a good idea to verify whether your variables contain what you think they do. For that, I recommend var_dump():
$connection_string = 'odbc:DRIVER={Microsoft ....';
var_dump($connection_string);
It's worth noting that everything I've explained is related to basic PHP syntax. Neither PDO nor Access issues have come up so far. It always help to isolate your issues.