我在 MySQL 数据库中有一个包含 varchar 的字段。此 varchar 旨在成为将用于引用文件位置的字符串。例如,/file.php
。
我已经设法获取这个 varchar 并使用下面的代码将它存储在 $locationarray
中:
$query4 = mysql_query("select filelocation from users where username='$username' limit 1");
while($rowloc = mysql_fetch_assoc($query4))
{
$locationarray = $rowloc['filelocation'];
}
但是,当我将 $locationarray
与 include()
函数结合使用时,屏幕上没有任何显示吗?
有没有办法从 MySQL 数据库中获取数据,可以与 include()
一起使用?
最佳答案
问题不在于您的包含代码,我怀疑它与 filelocation 的内容有关。
/file.php
是绝对路径,因此 include 会在系统根目录中查找 file.php
。
Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include() will finally check in the calling script's own directory and the current working directory before failing. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error.
来源:http://uk3.php.net/manual/en/function.include.php
检查您的错误日志 - 如果找不到该文件,该日志将准确告诉您 include
正在查找的位置。
关于php - 从可以与 include() 一起使用的 MySQL 数据库中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5382610/