Reputation: 5449
I am trying to use ODBC with php and I seem to be having some problems. This is my code:
<?php
$connect = odbc_connect("digitallibrary", "root", "");
$sql = "SELECT name FROM books";
$result = odbc_exec($connect, $sql);
echo $result;
while (odbc_fetch_row($result)) {
$name = odbc_result($result, "name");
print("$name\n");
}
odbc_close($connect);
?>
I have also installed mysql odbc connector and added this system DSN: Datasource Name : digitallibrary TCP/IP Server: localhost Port 80 user: root database:digitallibrary
When I run my code I get this warnings but nothing printed:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application, SQL state IM014 in SQLConnect in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 9
Warning: odbc_exec() expects parameter 1 to be resource, boolean given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 11
Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 14
Warning: odbc_close() expects parameter 1 to be resource, boolean given in E:\Program Files\xampp\htdocs\DigitalLibrary\index.php on line 18
what am I doing wrong?
Upvotes: 0
Views: 8828
Reputation: 15229
Now, You are attempting to use a 64 bit application with a 32 bit ODBC driver or vice versa. You should check that what are you using the PHP application 64 bit or 32 bit. After that you have to start the correct ODBC administrator. There are 2 types which are 32 bit
and and 64 bit
.
If you are using 64 bit ODBC administrator: It is in Adminstrative tools, control panel
If you are using 32 bit ODBC administrator: You should go into the path
%windir\syswow64\odbcad32.exe.
When you have set the right ODBC administrator. You will also need to create the system DSN. If you cannot find the MS Access driver in the administrator you'll need to download one for that architecture.
EDIT : you can download the 32 bit from here
Hope this helps.
Upvotes: 2