PHP --> MSSQL Cursor Error When More Then 1 Include

Hi,
I'm trying to connect to an MSSQL database using ODBC/PHP on Linux.   When I have a file (index.php) and just do an include to the connect.inc file (see below) it works fine.  However, when I have a file (index.php) and do an include to a file include.inc which then includes connect.inc I get cursor errors.. any help?

ERROR:
Warning: odbc_exec(): SQL error: [unixODBC][FreeTDS][SQL Server]Invalid cursor state, SQL state 24000 in SQLExecDirect in /home/voip/userinterface/site/overview.php on line 6


index.php page: (when it isn't working):
<?
include("../includes/includes.inc");

$connect = mssqlConnection();
$query = "Select TOP 10 calldate,src,billsec,clid from cdr where dst = '$number' order by calldate desc";
$result = odbc_exec($connect,$query);

?>


../includes/includes.inc:
<?
require("session_check.inc");
require("hackcheck.inc");
require("connect.inc");
require("header.php");
?>

connect.inc:
<?
function mysqlConnection()
{
        $Uid = "removed";
        $Pwd = "removed";
        $host = "removed";

        @ $db = mysql_connect($host, $Uid, $Pwd);
        if (!$db)
        {
         die(mysql_error());

                echo "Error: Could not connect to database.";
                exit;
        }
        mysql_select_db("asterisk");
        return $db;

}

function mssqlConnection()
{
        $uid = "removed";
        $pwd = "removed";
        $odbc = "removed";

        $connect = odbc_connect($odbc,$uid,$pwd);
        return $connect;
}

?>


Any thoughts?
LVL 1
hazmatt81Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
try to use include_once instead of include
hazmatt81Author Commented:
That doesn't seem to work either..
JKlatteCommented:
Try using include() instead of require() - it could be that some php notice or warning is interrupting the script.

From the PHP docs: the two constructs are identical in every way except how they handle failure: include() produces a warning while require() results in a fatal error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

hazmatt81Author Commented:
Already tried that... still no go =(
iamanindianCommented:
Is this the first time you are trying to connect to MSSQL on the system? Has any past attempt worked out?

Instead of the current query...i.e.
$query = "Select TOP 10 calldate,src,billsec,clid from cdr where dst = '$number' order by calldate desc";

Can you try running a simple query like:
$query = "Select count(clid) from cdr"; //or whatever

This will ensure we are not doing anything wrong with query atleast.
Then accordingly we can think of 2nd level troubleshooting :)

Regards
WC


hazmatt81Author Commented:
Yeah doing something like you suggested works.. and a connection can be established.
iamanindianCommented:
Ok...if a different query works, but the one you tried actually i.e.
--------------------------------------------------------------------------------------------------------------------------------
$query = "Select TOP 10 calldate,src,billsec,clid from cdr where dst = '$number' order by calldate desc";
--------------------------------------------------------------------------------------------------------------------------------
doesn't work...then it is needed to check the table (the data types in particular). Most likely the dst (or one of the calldate/src/billsec/clid) has a data type mismatch. What is the field type on "dst" & what does $number return?
Check that part...perhaps your problem is there.

Best
WC

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.