我有一個名爲config.php文件這個mysqli_connect:mysqli_connect從包含的文件不工作
$DbServer = 'localhost';
$DbUser = 'username';
$DbPassword = 'password';
$DbName = 'dbname';
$con = mysqli_connect($DbServer, $DbUser, $DbPassword, $DbName);
然後我還有一個PHP文件名爲sendingrequest.php:
<?php
session_start();
require_once ('config.php');
$Key = mysqli_real_escape_string ($con, $_GET["key"]);
...
?>
這sendingrequest.php總是產生此錯誤消息:
Warning: mysqli_real_escape_string(): Couldn't fetch mysqli in /home/public_html/sendingrequest.php on line 4
我試圖把mysqli_connect修改腳本()在同一個文件,而不是require_once()了,令人驚訝它的工作原理...
<?php
session_start();
//require_once ('config.php');
$DbServer = 'localhost';
$DbUser = 'username';
$DbPassword = 'password';
$DbName = 'dbname';
$con = mysqli_connect($DbServer, $DbUser, $DbPassword, $DbName);
$Key = mysqli_real_escape_string ($con, $_GET["key"]);
...
?>
有什麼錯我的require_once?爲什麼mysqli_real_escape_string未能使用它?謝謝!
我能看到的唯一原因是'require_once'config.php';'失敗。試試這個簡單的例子:'<?php ini_set('display_errors',1); require_once'config.php'; ?>它工作嗎? – hek2mgl