Connecting to DoyleSoft Knowledge Base via PHP and ODBC
PLEASE NOTE: Security policies are beyond the scope of this document. Please discuss security with your web host or network administrator.
ODBC is an Application Programming Interface (API) that allows you to connect to a data source (e.g. an MS Access database). 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:
1. Open odbcad32 by clicking Start | Run and typing odbcad32 in the Open line.Note that this configuration has to be done on the computer where your web site is located. If your web site is located on a remote server, you have to have access to that server, or ask your web host or network administrator to set up a DSN for you to use.
2. Choose the System DSN tab.
3. Click on Add in the System DSN tab.
4. Select the Microsoft Access Driver. Click Finish.
5. In the next screen, click Select to locate the database.
6. Give the database a Data Source Name (DSN).
7. Click OK.
Now, setup your index.php file as displayed below:
<html> <body>
<?php
$conn=odbc_connect('KB','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM KB";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
echo "<table><tr>";
echo "<th>KBTitle</th>";
echo "<th>KBProblem</th></tr>";
while (odbc_fetch_row($rs))
{
$KBTitle=odbc_result($rs,"Title");
$KBProblem=odbc_result($rs,"Problem");
echo "<tr><td>$KBTitle</td>";
echo "<td>$KBProblem</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>
</body> </html>
|
Sign up for the free DoyleSoft Newsletter! Your email address will be kept confidential, and will only be used to send you our free newsletter.
|
