Entry
How do I connect to an ODBC database?
Where can I get an example of an ODBC session?
May 10th, 2000 05:31
Gergely Szenes, Nathan Wallace, Riley Breiddal
Code for an ODBC connection:
$myDB = odbc_connect("Movies","","");
$query = "SELECT * FROM MovieList";
$result = odbc_exec($myDB, $query);
$report = odbc_fetch_row($result);
echo odbc_result($result, 1);
odbc_close($myDB);
This code would goto whichever database you have declared as "Movies" in
your System DSN list with no login or password. Then using $query (if
you don't know SQL, write your query using that Access Design View, then
switch to SQL View, and it'll show you the 'code' for it). The rest is
straightforward, just prints out the first field of the first row in the
database.
About the DSN's, if you operate your server, (I'm assuming your on NT :)
just goto ODBC Data Sources in Control Panel and add your database to
System DSN.
Driver = Access.
Data Source Name = (in this example) "Movies".
Just a tip:
Php4rc1 with Oracle DB through ODBC won't work anyway! Bug.
Try PHP3 or see that if php4rc2 works or not.
If you're interested in PHP's bugs have a look at
http://marc.theaimsgroup.com/?l=php-dev&w=2&r=1&s=odbc&q=b