Author Topic: PHP & ODBC  (Read 2236 times)

technode

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
PHP & ODBC
« on: April 17, 2008, 02:25:17 PM »
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:

Quote
Warning: odbc_connect() [function.odbc-connect]: SQL error: , SQL state 00000 in SQLConnect in C:Program FilesApache Software FoundationApache2.2htdocsODBCtestingODBCconnect.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.

Code: [Select]
$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>";


Thanks in advance for your help.

peg110

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 799
  • Karma: +0/-0
    • View Profile
    • http://www.tripleclicks.com/11260983/go
Re: PHP & ODBC
« Reply #1 on: April 23, 2008, 02:43:51 PM »
If it's a MySQL DB Server, why are you using ODBC? or even DSN's for that fact.

mysql_connect

mysql_select_db and mysql_query
or
mysql_db_query

Then

mysql_fetch_XXXX (assoc, array, etc...)

technode

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: PHP & ODBC
« Reply #2 on: April 24, 2008, 08:50:33 AM »
It is a proprietary DB (that is a MySQL, but you can't connect to the stored procedures and data that way). ODBC is the only way to pull the data out.

Zyppora

  • Global Moderator
  • Senior Member
  • *****
  • Posts: 1401
  • Karma: +0/-0
    • View Profile
Re: PHP & ODBC
« Reply #3 on: June 13, 2008, 06:34:19 AM »
According to this bug page it's possible that using the latest stable version of PHP might provide a solution to this issue. What's your PHP version?
HAVE YOU TRIED DEBUGGING? Example code in this reply deliberately contains BUGS. PHP forum for beginners.