What is the error in getting an info from MSSQL? Enclosed herewith: an error message and source of the program

[Fri Feb 22 12:54:15 2008] [error] [client 132.64.4.16] PHP Warning: odbc_exec() [function.odbc-exec]: SQL error: [unixODBC][FreeTDS][SQL Server]Could not find stored procedure 'SHOW'., SQL state 37000 in SQLExecDirect in /srv/www/htdocs/hu/Proj1/test.php on line 9
[Fri Feb 22 12:54:15 2008] [error] [client 132.64.4.16] PHP Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in /srv/www/htdocs/hu/Proj1/test.php on line 10
[Fri Feb 22 12:54:15 2008] [error] [client 132.64.4.16] PHP Warning: odbc_free_result(): supplied argument is not a valid ODBC result resource in /srv/www/htdocs/hu/Proj1/test.php on line 14

The test source program is:

--- begin odbctest.php---
<?
// connect to DSN MSSQL with a user and password
$connect = odbc_connect("DSNNAME", "user", "passwd") or die
("couldn't connect");
print "connection ok";
odbc_exec($connect, "use SwitchCenterDB");
print "SwitchCenterDB ok";
$result = odbc_exec($connect, "SHOW TABLES");
while(odbc_fetch_row($result)){
print(odbc_result($result, "CompanyName") .
' ' . odbc_result($result, "ContactName") . "\n");
}
odbc_free_result($result);
odbc_close($connect);
?>
--- end odbctest.php --

same here

R's picture

we encountered same problem:
[Fri Feb 22 12:54:15 2008] [error] [client 132.64.4.16] PHP Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in /srv/www/htdocs/hu/Proj1/test.php on line 10

as

Warning: odbc_fetch_row(): 9 is not a valid ODBC result resource in /var/www/localhost/htdocs/customer.microprecision.com/gage.php on line 182

and my code:

<?
odbc_close($conn1);
// List Events For This Instrument
$conn2=odbc_connect($db_host,$db_user,$db_pass);
$sql2="SELECT * FROM events where events.company = '$custid' and ".
"gage_sn = '$cal' and ".
"(event_type like '%cal%' or event_type = 'Repair' or event_type = 'Op-Check')";
//echo $sql2;
//echo $cal;
$rs2=odbc_exec($conn2,$sql2);
if (!$rs2)
{exit("Error in SQL");}
?>

Event Type
Documents
Cal Date
Calibration Result

<?
odbc_fetch_row($rs2, 0);
while (odbc_fetch_row($rs2)) <------line 182------>
{
$etype=trim(odbc_result($rs2,"event_type"));
$enum=odbc_result($rs2,"event_num");
$edate=odbc_result($rs2,"event_date");
$edate = date("M-j-Y", strtotime($edate));
$eresult=trim(odbc_result($rs2,"event_result"));
?>

i wonder how you solve this one? i wish that you can help me. please send me an email --> ran.september@gmail.com thanks!

Bad SQL

paul.bohme's picture

The first error is the real one: You're feeding it something it doesn't know how to deal with. A bit of googling comes up with 'show tables' being a MySQL-ism - not something SQL Server is going to understand.

The other errors come from not checking the result set before trying to use it. ;-)

I am by no means an expert

Mike Roberts's picture

I am by no means an expert on your topic but something did catch my eye. The line in your sample code:
print(odbc_result($result, "CompanyName") .
' ' . odbc_result($result, "ContactName") . "\n");

appears to me to have an extra ) between "\n" and the ;

Just a guess but if that is really in the code that could be all or part of the problem.

Happy hunting!

Mike Roberts is a bewildered Linux Journal Reader Advisory Panelist.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState