好吧我寫了一個自定義的PHP函數來從MySQL DB中提取一個值,原本這個函數是在一個類中,我試圖從類中調用它,它不斷給我帶來麻煩,所以我因爲我沒有收到500以外的任何錯誤,所以我沒有在/ var/log/httpd/error_log中看到任何錯誤,並且如果我將$ host變量註釋掉,我將其稱爲getSetting函數腳本剛纔說沒有登錄這是預期的,因爲我不提供任何信息到ssh登錄方法。自定義PHP函數HTTP錯誤500
<?php
//testing for php
//created by dylan kraklan do not use without permission
//setenforce 0 on host machine is required
//header('Content-type: text/plain');
error_reporting('E_ALL | E_STRICT');
ini_set('display_errors', 'On');
include('Net/SSH2.php');
include('general.php');
include('config.php');
$database =Database::getInstance();
$db = $database->getConnection();
$gen = new Gen();
function getSetting($setting) {
$set_sql = "SELECT value FROM settings WHERE setting='$setting'";
$set_query =$db->query($set_sql);
$value_a = $set_query->fetch_assoc();
$value =$value_a['value'];
return $value;
}
$host = getSetting('remote_host');
//$user = $gen->getSetting('remote_user');
//$pass = $gen->getSetting('remote_pass');
//echo $host.$user.$pass;
$ssh = new Net_SSH2($host);
if(!$ssh->login($user, $pass)) {
exit('Login Failed');
}
print_r($ssh->exec('pwd'));
print_r($ssh->exec('ls -la'));
?>
我啓用了所有我在php.ini中看到的錯誤日誌optiosn,我甚至指定日誌錯誤php_error.log,我以爲這個文件將在同一目錄爲php.ini文件(在/ etc )沒有看到它產生。然後我試着將它切換到/var/log/httpd/php_error.log,但我仍然沒有看到它生成。
編輯:好了,所以我發現一些代碼,會告訴我的錯誤,PHP's white screen of death
現在的錯誤是
E_NOTICE Error in file �test.php� at line 21: Undefined variable: db Fatal error: Call to a member function query() on a non-object in /var/www/html/sync/lib/test.php on line 21 E_ERROR Error in file �test.php� at line 21: Call to a member function query() on a non-object
線路21
$set_query =$db->query($set_sql);
我不知道我的mysql語句有什麼問題,但它似乎是導致問題。
可能重複[PHP的死亡白屏](http://stackoverflow.com/questions/1475297/phps-white-screen-of-death) – Sherif