# connect to a DSN "mydb" with a user and password "marin"
$connect = odbc_connect("mydb", "marin", "marin");
# query the users table for name and surname
$query = "SELECT name, surname FROM users";
# perform the query
$result = odbc_exec($connect, $query);
# fetch the data from the database
while(odbc_fetch_row($result)){
$name = odbc_result($result, 1);
$surname = odbc_result($result, 2);
print("$name $surname\n");
}
# close the connection
odbc_close($connect);
?>
Showing posts with label PHP ODBC Connection function. Show all posts
Showing posts with label PHP ODBC Connection function. Show all posts
Wednesday, November 14, 2007
Connecting to ODBC and PHP
PHP Database ODBC Connection
ODBC is an Application Programming Interface (API) that allows you to connect to a data source (e.g. an MS Access database).
Create an ODBC Connection
With an ODBC connection, you can connect to any database, on any computer in your network, as long as an ODBC connection is available.
Here is how to create an ODBC connection to a MS Access Database:
- Open the Administrative Tools icon in your Control Panel.
- Double-click on the Data Sources (ODBC) icon inside.
- Choose the System DSN tab.
- Click on Add in the System DSN tab.
- Select the Microsoft Access Driver. Click Finish.
- In the next screen, click Select to locate the database.
- Give the database a Data Source Name (DSN).
- Click OK.
Subscribe to:
Posts (Atom)