odbc_exec - returns nothing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phamot
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2010 2:14 pm

odbc_exec - returns nothing

Post by phamot »

Hi Everyone:

I am a little new to PHP, so I apologize if this is alot simpler than what I'm making it out to be.

I am attempting to execute some SQL through an ODBC driver, and I seem to have some difficulty in returning the results.

I know my ODBC driver works (I can run the same query through Crystal Reports just fine using the same ODBC driver), but PHP returns no values. I'm starting with a simple script (see below), which ultimately I'd like to put the results into an array for another function. I was able to get this to work on PHP4, but I cannot seem to get this to work on PHP5. I can see on my application logs that I am connecting, but it doesnt seem like the script is executing the query properly.

I get results for $connect and $query, but I get nothing for $result (which according to the PHP documentation, I should get an ODBC result identifier if the SQL command was executed successfully, or FALSE on error. In my case I get absolutely nothing.

Code: Select all

<?php
$connect = odbc_connect('ARSystem', '<username>', '<password>');
$query = "SELECT Change_#, Status FROM CM_Change_Management WHERE Status = 'Draft'";
$result = odbc_exec($connection, $query);
print $connect;
print $query;
print $result;
?>
Any help would be greatly appreciated
phamot
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2010 2:14 pm

Re: odbc_exec - returns nothing

Post by phamot »

I forgot to mention that this is a System DSN ODBC driver too.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: odbc_exec - returns nothing

Post by AbraCadaver »

It is returning something:

Code: Select all

var_dump($result);
To get rows of data from that you need to use one of the odbc_fetch_*() functions.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
phamot
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2010 2:14 pm

Re: odbc_exec - returns nothing

Post by phamot »

Hi AbraCadaver

Well, that definitely got me farther :D

I just added the var_dump($result); after the odbc_exec per your suggestion, but it returned "NULL". :(

Could it be something with my connection or that I didn't output the results (using odbc_fetch_*)?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: odbc_exec - returns nothing

Post by AbraCadaver »

That's strange. I don't use odbc functions but it is very similar to the other PHP DB functions. Try this to see if there is an error:

Code: Select all

$result = odbc_exec($connection,  $query) or die(odbc_errormsg());
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
phamot
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2010 2:14 pm

Re: odbc_exec - returns nothing

Post by phamot »

Just get a blank screen - its very odd.

I'm starting to wonder if my php install is messed up (I used the manual one).
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: odbc_exec - returns nothing

Post by AbraCadaver »

Try this:

Code: Select all

$result  = odbc_exec($connection,  $query) or die(odbc_errormsg($connection));
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
phamot
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2010 2:14 pm

Re: odbc_exec - returns nothing

Post by phamot »

Hi Shawn:

Still no luck - I actually ended up creating a whole new instance using PHP5 and I simply cannot get any results to return at all - here is my PHP Code:

Code: Select all

<?php
$conn = odbc_connect('ARsystem71', '<username>', '<password>');
$query = "SELECT Change_#, Status from CM_Change_Management where Status = 'Draft'";
$result = odbc_exec($conn, $query) or die(odbc_errormsg());
var_dump($num_rows);
print $conn;
print $query;
print $result;
print $num_rows;
?>
The funny thing is that this worked beautifully when I had it in PHP4 - I cant tell if its the driver or what the problem is.
phamot
Forum Newbie
Posts: 6
Joined: Wed Jul 07, 2010 2:14 pm

Re: odbc_exec - returns nothing

Post by phamot »

I think I may have this figured out - looks like my driver didn't like PHP5 :?

I finally was able to run a query & give me the # of Rows back - not exactly where I need to be but definitely a start!

Thanks for your help!
Post Reply