Home > Backend Development > PHP Tutorial > php多次引用出错

php多次引用出错

WBOY
Release: 2016-06-06 20:18:49
Original
1479 people have browsed it

以前没有这个问题,php升级到5.4出现这个问题

config.php中代码

<code><?php define('host','localhost');
define('username','root');
define('password','root');
define('database','daan');
?></code>
Copy after login
Copy after login

connect.php中代码

<code><?php require_once 'config.php';
$mysqli = new mysqli(host,username,password,database);
if($mysqli->connect_error)
{
    die('Connect Error:'.$mysqli->connect_error);
}
$mysqli->set_charset('utf8');
?></code>
Copy after login
Copy after login

index.php中的代码

<code><?php require_once 'connect.php';
?></code>
Copy after login
Copy after login

接下来问题来了,如果我在index.php中单单引入connect.php,php报错,提示我host username password datebase这几个常量没有定义
但如果这样

<code><?php require_once 'config.php';
require_once 'connect.php';
?></code>
Copy after login
Copy after login

就正常了,请问这是怎么回事,如何解决

回复内容:

以前没有这个问题,php升级到5.4出现这个问题

config.php中代码

<code><?php define('host','localhost');
define('username','root');
define('password','root');
define('database','daan');
?></code>
Copy after login
Copy after login

connect.php中代码

<code><?php require_once 'config.php';
$mysqli = new mysqli(host,username,password,database);
if($mysqli->connect_error)
{
    die('Connect Error:'.$mysqli->connect_error);
}
$mysqli->set_charset('utf8');
?></code>
Copy after login
Copy after login

index.php中的代码

<code><?php require_once 'connect.php';
?></code>
Copy after login
Copy after login

接下来问题来了,如果我在index.php中单单引入connect.php,php报错,提示我host username password datebase这几个常量没有定义
但如果这样

<code><?php require_once 'config.php';
require_once 'connect.php';
?></code>
Copy after login
Copy after login

就正常了,请问这是怎么回事,如何解决

看下这个应该对你有帮助,在回家的路上没法码字
http://m.111cn.net/art-42982.htm

试试将定义的常量名改成大写的试试吧

new mysqli(host,username,password,database);
new mysqli($host,$username,$password,$database);
懂了吗?

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template