Jump to content

PHP & ODBC


technode

Recommended Posts

I have set up an ODBC driver to a MySQL DB. Excel can connect and retreive data from the DB via this ODBC DSN. However when I write a php script to access the DSN I get:

 

Warning: odbc_connect() [function.odbc-connect]: SQL error: , SQL state 00000 in SQLConnect in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ODBCtesting\ODBCconnect.php on line 9

 

Line 9 is the call to the password. Excel does not use us username or password to connect to the ODBC, the ODBC has the user & pass for the MySL DB.

 

Thanks in advance for your help.

Link to comment
Share on other sites

$DSN='WebTrends Testing DSN';

$DSNuser='connerys';

$DSNpass='29080';

$conn=odbc_connect("WebTrendsDSNtest2","","");

 

if (!$conn)

  {exit("Connection Failed: " . $conn);}

$sql="SELECT Browsers_0.Browser, Browsers_0.Visits, Browsers_0.TimePeriod, Browsers_0.StartDate, Browsers_0.EndDate

FROM Browsers Browsers_0

WHERE (Browsers_0.TimePeriod='2008.m03')

ORDER BY Browsers_0.Visits DESC, Browsers_0.Browser DESC";

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

if (!$rs)

  {exit("Error in SQL");}

echo "<table><tr>";

echo "<th>Browsers_0.Browser</th>";

echo "<th>Browsers_0.Visits</th></tr>";

while (odbc_fetch_row($rs))

{

  $compname=odbc_result($rs,"Browsers_0.Browser");

  $conname=odbc_result($rs,"Browsers_0.Visits");

  echo "<tr><td>$Browsers_0.Browser</td>";

  echo "<td>$Browsers_0.Visits</td></tr>";

}

 

//close ODBC

odbc_close($conn);

echo "</table>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.