Home > php教程 > php手册 > set_include_path和get_include_path使用及注意事项

set_include_path和get_include_path使用及注意事项

WBOY
Release: 2016-06-13 11:55:30
Original
831 people have browsed it

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');  //实例化和之后的查询语句并无错误

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template