Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Blog
Books
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links






 
 

SPONSORS



 
 

Display an Access Database

For this code to work you need to create an ODBC data source , this can be achieved in Windows by going to Control Panel and locationg ODBC data sources or in Windows 2000 in the administrative tools section you will find Data Sources (ODBC) . We have supplied the database for you in a zip file at the bottom of the page.

Here is the code

<?php
//our dsn
$odbcdsn = "sampledb";
$odbcuser = "";
$odbcpassword = "";
//the sql query
$sqlquery = "SELECT * FROM tblsample";
//connect to our database
if(!($odbcdb = odbc_connect($odbcdsn , $odbcuser , $odbcpassword)))
die("couldnt connect to ODBC data source");
//execute the query against the dat source
if(!($odbcrs = odbc_do($odbcdb , $sqlquery)))
die("cannot execute query");
//find out how may colums of data are present
$columns = odbc_num_fields($odbcrs);
//if no columns of data , exit graciously
if($columns < 1) die("query returned an empty set")
?>
</p>
<table>
<tr>
<?php
//display column headings
for($i = 1 ; $i <= $columns ; $i++)
{
?>
<th>
<?php
echo odbc_field_name($odbcrs, $i);
?>
</th>
<?php
}
?>
</tr>
<?php
//create a new table row and display contents then close
//it
while(odbc_fetch_row($odbcrs))
{
?>
<tr>
<?php
//
for($i=1;$i<=$columns;$i++)
{
$data = odbc_result($odbcrs, $i);
echo "<td>$data</td>";
}
?>
</tr>
<?php
}
?>
</table>


Download

sampledb.zip