I have a function in function.php which outputs okay when calling inside the file, but if I include function.php in another file and call the function I get error.
Here is my function.php
$mysqli = new mysqli('localhost','dbuser','dbpassword','dbname');
if( $mysqli->connect_error ) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
mysqli_set_charset($mysqli,"utf8");
}
$date=$mysqli->real_escape_string($_GET["date"]);
if(!empty($date)) {
$date = $mysqli->real_escape_string($_GET['date']);
} else {
$date = date("Y-m-d", strtotime('today'));
}
function functionname() {
global $mysqli, $date;
$sql=mysqli_query($mysqli,"SELECT * FROM database WHERE DateLT= '".$date."'");
if(mysqli_num_rows($sql) > 0) {
echo "somedata";
while($row = mysqli_fetch_array($sql))
{
echo "somedata";
}
} else {
}
}
functionname()
$mysqli->close();
/*-->*/
Output okay. But if i call function from example.php like this,
<?php define('ROOT', $_SERVER['DOCUMENT_ROOT']);
include(ROOT."/function/function.php");
functionname();?>
I get mysqli error.
mysqli_close($mysqli)anywhere? If you close the connection and then try to callfuncctionname()you'll get that error.