Home  >  Article  >  Backend Development  >  set_include_path和get_include_path使用及注意事项_php技巧

set_include_path和get_include_path使用及注意事项_php技巧

WBOY
WBOYOriginal
2016-05-17 09:07:03793browse

set_include_path 设置默认包含路径
在include或require文件的时候,先在默认包含路径里面找,然后在同目录下找
例:
D:/xampp/htdocs/test/include  下有一文件为cls.mysqli.php
D:/xampp/htdocs/test/  下有一文件为set_include_path.php
里面的内容为

复制代码 代码如下:

set_include_path('/xampp/htdocs/test/include');  //请注意php里边的'/'代表的不是网站根目录,而是文件所在的盘符,可用echo realpath('/');查看
//若php版本过低,该函数不支持,可用通用版ini_set()
/*查看真实默认包含路径*/
echo realpath(get_include_path());
/*要包含cls.mysqli.php只需要*/
require_once('cls.mysqli.php');
$mysql = new Mysql('localhost','root','','test');  //实例化和之后的查询语句并无错误
Statement:
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