我使用phpmyadmin和MySQL創建了一個數據庫表。我試圖建立一個連接到我的數據庫使用PHP腳本。我搜索了所有人,並找到了正確的語法和腳本來建立一個簡單的連接。當我在我的活服務器上運行php文件時,瀏覽器只顯示php文件的實際代碼,而不是錯誤消息或任何輸出。無法建立連接到MySQL數據庫使用PHP
這是我的PHP腳本,我正在與。
<?php
$username = "*******";
$password = "********";
$hostname = "*********";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL <br>";
?>
對於什麼可能會導致我完全沒有輸出的幫助或方向?
請[停止使用'mysql_ *'函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [這些擴展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中刪除。瞭解[編寫](http://en.wikipedia.org/ wiki/Prepared_statement)語句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)並考慮使用PDO,[這真的很簡單](http://jayblanchard.net/demystifying_php_pdo.html)。 –
你確定你有一個Apache服務器啓動? – Mihai
得到*實際的錯誤與'或死亡(mysql_error())'。或者您可以在當前的錯誤日誌中找到問題。 –