Hi to all,
I have a problem with php-odbc connecting to access db.
I followed instructions for configuration the ODBC Administrator:
1. Go ahead and create an Access database. I’ll assume that you know how
to do this already. If you don’t, but still want to follow along with this
example, just quickly create a database using the Access Wizard. For this
example, I created the predefined Contact Management Database using
the wizard. Be sure to insert some information into a table and take note
of that table name, as you will need it in a while!
Save the database somewhere on your computer.
Now it’s time to make that Access database available using ODBC. Go to
Start -> Settings -> Control Panel. You should see an icon entitled “ODBC
Data Sources (32 bit).” This is the ODBC Administrator, used to handle
the various drivers and database sources on the system. Open this icon
by double-clicking it. The window will open to the default tabbed subwindow
entitled “User DSN (User Data Sources).” The User DSN contains
the data sources specific to a single user and can be used only on this
machine. For sake of this example, we’ll use this.
Click the Add… button on the right side of this window. A second window
will open, prompting you to select a driver for which you want to set up a
data source. Choose the Microsoft Access Driver (*.mdb) and click Finish.
A new window will open, entitled “ODBC Microsoft Access Setup.” You’ll
see a form text box labeled “Data Source Name.” Enter a name relative to
the Access database that you created. If you would like, enter a description
in the text box directly below that of the Data Source Name.
Now click the Select… button displayed on the middle left of the window.
An Explorer-style window will open, prompting you to search for the
database that you would like to make accessible via ODBC.
Browse through the Windows directories to your database. When you find
it, double-click it to select it. You will return to the ODBC Microsoft
Access Setup window. You’ll see the path leading to the selected database
directly above the Select… button. Click OK.
That’s it! Your Access database is now ODBC enabled.
('Programmers Introduction to PHP4')
Then I tried to run this script:
<?
// Connect to the ODBC datasource 'accessBase1'
$connect = odbc_connect("accessBase1","","") or die("Couldn't connect to datasource.");
// form query statement
$query = "SELECT productID, productName, unitPrice FROM products";
// prepare query statement
$result = odbc_prepare($connect,$query);
// execute query statement and display results
odbc_execute($result);
odbc_result_all($result,"border=1");
// We're done with the query results, so free memory
odbc_free_result($result);
// close connection
odbc_close($connect);
?>
& this is what I receive : "Couldn't connect to datasource." :xbones:
So, what could be wrong here ?
This access db is named acc1.mdb (not accessBase1).
Does anyone know what are the username & password from odbc_connect function (.... ,"","")?
I left those fields empty, because I didn't set usnm&passw for acc1.mdb .
If there are default ones (perhaps just username), please let me know.
Access permission for acc1.mdb is set to FULL to everyone.
(I'm running PHP 4.3.11 & MySQL 4.1)
Thanks a lot !