note 116151 added to ref.pdo-odbc.connection

From: Date: Sat, 15 Nov 2014 14:45:08 +0000
Subject: note 116151 added to ref.pdo-odbc.connection
Groups: php.notes 
Request: Send a blank email to php-notes+get-200916@lists.php.net to get a copy of this message
$dbname = 'mydb'; $username = 'admin'; //username is ignored $password = ''; //can be set in Access $dbnameFile = $_SERVER["DOCUMENT_ROOT"] . "/subdir/".$dbname.".accdb"; if (!file_exists($dbnameFile)) die("Could not find database file.".$dbnameFile); $s="odbc:Driver=Microsoft Access Driver (*.mdb, *.accdb);Dbq=$dbnameFile;Uid=$username;PWD=$password"; echo $s."<br />"; $db = new PDO($s); echo 'Connected to database'; If you want to set a password for an Access database open it Exclusive by starting Access and choosing File > Open > Browse to file > Open Exclusive (use dropdown in FileDialog). I also that the Driver=... part of the connection string must be typed in exactly. Before this I used odbc:Driver=Microsoft Access Driver (*.accdb) but that didn't work. I got an error 'Data source name not found and no default driver specified'. I found out about this when using 'set up data sources (ODBC)' program in Windows 7. I noticed there the driver was named differently! It's also allowed to use {...} around the drivername: odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=$dbnameFile;Uid=$username;PWD=$password ---- Server IP: 72.52.91.14 Probable Submitter: 88.159.84.129 ---- Manual Page -- http://php.net/manual/en/ref.pdo-odbc.connection.php Edit -- https://master.php.net/note/edit/116151 Del: integrated -- https://master.php.net/note/delete/116151/integrated Del: useless -- https://master.php.net/note/delete/116151/useless Del: bad code -- https://master.php.net/note/delete/116151/bad+code Del: spam -- https://master.php.net/note/delete/116151/spam Del: non-english -- https://master.php.net/note/delete/116151/non-english Del: in docs -- https://master.php.net/note/delete/116151/in+docs Del: other reasons-- https://master.php.net/note/delete/116151 Reject -- https://master.php.net/note/reject/116151 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200916) next »