Page 1 of 1
include statement
Posted: Thu Apr 28, 2011 6:57 pm
by ModusPonens
Not sure if I'm having a problem with my ini file or if there's something wrong with the structure of my programming.
abc.php
<?PHP
include ("def.php");
doDB();
$result = mysqli_query($Con, "call sp_getdata;");
.
.
.
?>
def.php
<?PHP
function doDB
{
global $Con;
$Con = mysqli_connect("localhost", "user", "password", "db");
.
.
.
}
?>
It's bombing on the bold line. I'm getting a recordset error, which tells me that $Con is not getting executed from the include file. I've changed the include path in the ini file several times. What am I overlooking?
Re: include statement
Posted: Thu Apr 28, 2011 8:50 pm
by fugix
i believe that "function doDB" should be "function doDB()"
Re: include statement
Posted: Thu Apr 28, 2011 9:21 pm
by ModusPonens
I know, I omitted the parens for brevity. they're in the code.
The frustrating thing is that if I instance the connection and execute the query from within "abc.php" it executes the way it is supposed to execute.
The actual message I'm getting is "PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in..." All I'm doing is populating some drop down list boxes. When I instance from within abc.php, the drop-downs fill properly, when I instance from the include file, they don't.
So the error is occurring at the line where I store the query results in $result, which invokes the connection object $Con.
Even added ini_set("include_path", "C:\web\watchmyteendrive"); above the include statement, and still nothing. I must be having a problem in a place where I'm not looking. I'm wondering if there's not something else in the php.ini that needs to be modified.
Re: include statement
Posted: Thu Apr 28, 2011 10:01 pm
by fugix
the only other thing that i can think of is to include the direct path to you def.php file...
Re: include statement
Posted: Fri Apr 29, 2011 7:44 am
by ModusPonens
fugix wrote:the only other thing that i can think of is to include the direct path to you def.php file...
I did that with the
ini_set above the include statement. Shouldn't make any difference, but I've written the include and the ini_set statements in the general code area outside the the function that makes the call to the function in the included function.
Re: include statement
Posted: Fri Apr 29, 2011 7:53 am
by fugix
i would set the $con value in the def.php and call it out on your other page...to make sure that the include is working properly
Re: include statement
Posted: Fri Apr 29, 2011 5:03 pm
by ModusPonens
fugix wrote:i would set the $con value in the def.php and call it out on your other page...to make sure that the include is working properly
Set up a dummy php page that only called the included page. Set $Con = "string";, then tried to echo $Con from the calling page. Not working. Has to be one of the config files, but I have no idea, other than the include_path, what I need to set.
Re: include statement
Posted: Sun May 01, 2011 11:07 am
by ModusPonens
All right, figured out at least part of the problem. For some reason, the global declaration doesn't work. If I declare $Con global in the <head> tag on the calling page, or within the function in the included page, fetching the recordset bombs. If I just declare $Con locally in the called function from the include page, then pass the connection object back to the calling function, it works.
