My problem is,
This is the file that is being included ,
<?php
$dbhost = "localhost";
$dbuser = "****";
$dbpass = "***";
$dbname = "****";
$MYSQL_ERRNO = "";
$MYSQL_ERROR = "";
// Connect To Database
function db_connect() {
global $dbhost, $dbuser, $dbpass, $dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to $dbhost.";
return 0;
}
else if(!mysql_select_db($dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
?>
The main file has the following code to make db connection ,
<?php
require_once 'file.php';
$link_id = db_connect($dbname);
......
?>
But i got function undefined error.
Using Apache in Windows with PHP 5.3
1) Check relative paths for your includes.
2) Just because the PHP documentation says you can use
require_oncewithout parenthesis doesn’t mean you should. Stay consistent, userequire_once("file.php");.3) Be consistent with curly braces in your function. You’re missing one or two up there. I’d like to know if you rewrite your function the following way if it works:
And remember, checking your web server error logs usually helps.
Edit:
According to the comments for this answer, you’re not including the file you think you are. Use an absolute path for the include so you’re 100% sure of the file being included.