To connect to any ODBC database like MS-Access, php provides odbc_connect method.
Before you connect to any ODBC database you have to create a DSN for that database using Admin.Tools
You follow below steps to create a DSN.
// Connect to ODBC DB
$mysql="SELECT * FROM emp_db";
$myrecordset=odbc_exec($myconn,$mysql);
Before you connect to any ODBC database you have to create a DSN for that database using Admin.Tools
You follow below steps to create a DSN.
- Go to Administrative tools in control panel
- Click on Data Sources (ODBC)
- Follow steps on screen to create a dsn for database
- You can create dsn for any database which provides ODBC API.
Now Let's assume you have created one DSN called mydsn.
Example with code and syntax :-
// Connect to ODBC DB
$myconn=odbc_connect('mydsn','','');
$mysql="SELECT * FROM emp_db";
// Execute a query on ODBC db
$myrecordset=odbc_exec($myconn,$mysql);
//fetch records from recordset from ODBC database
while (odbc_fetch_row($myrecordset))
{
$age=odbc_result($myrecordset,"age");
{
$age=odbc_result($myrecordset,"age");
echo $age;
}
}
odbc_close($myconn);
//Close database connection
Above example show how we can connect to ODBC database like MS-Access using dsn and execute query on it.
No comments:
Post a Comment