PDA

View Full Version : Connecting to an access Database in PHP


qaak
09-03-2006, 02:37 AM
I tried this:

<code>

<?PHP
odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . str_replace("/", "\\", $_SERVER["DOCUMENT_ROOT"]) . "\_database\mydatabase.mdb", "", "");
?>


</code>

I got this error:
-----------------------------------------------


PHP Warning: odbc_connect(): SQL error: [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x3f40 Thread 0x2700 DBC 0x973dac Jet'., SQL state S1000 in SQLConnect in E:\web\localgirlso\htdocs\test\database.php on line 2

-----------------------------------------------

qaak
09-03-2006, 03:50 AM
I found the answer after many unsuccessful attempts but not too many http://community.discountasp.net/emoticons/scool.gif

[quote]

<?PHP
//YOURDIRECTORY is thedirectory specific to your account
//YOURDATABASE is the database you wish to connect to
//In this example the database contains a table called tblTest
$cfg_dsn = "DRIVER=Microsoft Access Driver (*.mdb);
DBQ=E:\\web\\YOURDIRECTORY\\htdocs\\_database\\YOU RDATABASE.mdb;
UserCommitSync=Yes;
Threads=3;
SafeTransactions=0;
PageTimeout=5;
MaxScanRows=8;
MaxBufferSize=2048;
DriverId=281;
";
$cfg_dsn_login = "";
$cfg_dsn_mdp = "";
$CID = odbc_connect($cfg_dsn,$cfg_dsn_login,$cfg_dsn_mdp) ;
$sql = 'SELECT ID, intQty, text
FROM tblTest
ORDER BY ID';
$cur = odbc_exec($CID, $sql);
?>
<table>
<tr>
<th>ID</th>
<th>Quantity Per Unit</th>
<th>Description</th>
</tr>
<?php while(odbc_fetch_row($cur))
{
//collect results
$ID=odbc_result($cur,1);
$qTy=odbc_result($cur,2);
$strText=odbc_result($cur,3);
//format and display results{ ?>
<tr>
<td><?php echo $ID ?></td>
<td><?php echo $qTy ?></td>
<td><?php echo $strText ?></td>
</tr>

<?php } ?>
</table>
<?php
//odbc_free_result($CID);
odbc_close($CID);
$rs = null;
$CID = null;
?>
</CODE>

wisemx
09-03-2006, 09:20 AM
Try this bro: http://www.google.com/microsoft?q=php+access+connection&amp;hq=microsoft