Activate PDO_OBDC drivers for PHP?

0

Sincerely since I do not touch php. Now at the University we will work with Arduino boards and we want to make a mini server with a web page hosted on it.

Well, as things are going to be simple, I have decided to use Access ... I've been doing some tests at home with notepad ++ and XAMPP , but when trying to connect to my database In access, I receive the following message:

Ok, the message is clear ... can not find the driver. I read in forums that what should be done is to enable the php_pdo_obdc.php extension in the php.ini file, which can be accessed easily by clicking on config, in the control of XXAMP. Well, the issue is that I added it, but it still does not work ... I do not know if I'm writing it in a bad place in the file or I just need to do something else.

How can I install the driver?

    try{    
        $bd = new PDO("odbc:DRIVER={Microsoft Access Driver (*.accdb)}; DBQ=$direccion; Pwd=contra;");
    }catch(PDOException $e){
        echo $e->getMessage();
    }

PHPInfo information

UPDATE

You have learned another thing now:

  

SQLSTATE [IM002] SQLDriverConnect: 0 [Microsoft] [ODBC Driver Manager] The name of the data source is not found and no default driver was specified

<?php
try{
    $dbName = "webData.accdb";
    $bd = new PDO("odbc:DRIVER={Microsoft Access Driver (*.accdb)}; DBQ=".realpath($dbName)."; Pwd=arduiccess;");
}catch(PDOException $e){
    echo $e->getMessage();
}
?>

I can not use those DBs with extensions .mdb , as you can notice.

    
asked by TwoDent 21.02.2017 в 22:55
source

1 answer

1

You must enable the PDO extension with the ODBC driver. In other words, in php.ini the line extension=php_pdo_odbc.dll must exist and the corresponding DLL must exist in the PHP EXT directory. Then, restart Apache.

Once this is done, if you do phpinfo() and look for the PDO section. I should say:

PDO drivers: mysql, odbc

Once that is done, you can instantiate the database (I suggest using the Access MDB format instead of the ACCDB):

try {
    $dbName = $_SERVER['DOCUMENT_ROOT'] . "webData.mdb";
    $bd = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Pwd=arduiccess;");
} catch(PDOException $e){
    echo $e->getMessage();
}

More info in the Sitepoint article Using an Access Database with PHP

    
answered by 25.04.2017 в 19:23