Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DSNless connection

Status
Not open for further replies.

mrsbean

Technical User
Jul 14, 2004
203
US
I'm learning PHP, slowly. I want to create a DSNless connection to work with Microsoft Access. I tried to modify a tutorial I found to create one. If I take out the ADODB in the following code, and use a plain old DSN, it works. What do I need to change to make this work (Windows server):

Code:
?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);

include("C:\\Inetpub\\adodb\\adodb.inc.php");

$mydb = "C:\\Inetpub\\database\\Nwind.mdb";

$conn = "PROVIDER=MSDASQL;DBQ=$mydb;"."DRIVER={Microsoft Access Driver (*.mdb)};UID=Admin;PWD=;" 
    $conn->open($conn); 

 

if (!$conn)  {exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM customers";
//The recordset = odbc_exec('the dsn connection', 'the sql statement')

$rs=odbc_exec($conn,$sql);

if (!$rs)
  {exit("Error in SQL");}
echo "<table><tr>";
echo "<th>Companyname</th>";
echo "<th>Contactname</th></tr>";
while (odbc_fetch_row($rs))
{
  $compname=odbc_result($rs,"CompanyName");
  $conname=odbc_result($rs,"ContactName");
  echo "<tr><td>$compname</td>";
  echo "<td>$conname</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>

</body>
</html>

Thanks in advance,

MrsBean
 
>> If I take out the ADODB in the following code, and use a plain old DSN

i dont get it, if u r using ADODB then DSN less connections should work...

Known is handfull, Unknown is worldfull
 
I guess that's right, providing that the user that is running the web-process has the necessary permission for the dsn-less connection
 
>>the necessary permission for the dsn-less connection

hmm, i always thought that just the drivers would do.

anyway from what angle is this permission required? database or the driver or the OS???

Known is handfull, Unknown is worldfull
 
you may be right. i thought you had to set up a machine or file based connection in the odbc set up in control panel (or wherever).
 
nope, ODBC files are not required for DSN less connections. the ADO object speaks directly with the driver DLLs.

Known is handfull, Unknown is worldfull
 
I just knocked out this:
Code:
<?php
$mydb = "c:\\kr\\tek\\tek.mdb";
$dsn = "PROVIDER=MSDASQL;DBQ=$mydb;"."DRIVER={Microsoft Access Driver (*.mdb)};UID=Admin;PWD=;"; 
echo "Connecting to $dsn \n";
$conn = odbc_connect($dsn,"","");
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);
while (odbc_fetch_row($rs))
{
  $cust=odbc_result($rs,"custname");
  $comment=odbc_result($rs,"comments");
  echo $cust . "\n";
  echo $comment . "\n";
}
?>
and it works ok.
Can you put a call into odbc_error and odbc_errormsg so we can see why it is failing ?
I've never used adodb, what does it give you that the ODBC layer does not - is it purely you use oledb ??.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top