2017-03-09 328 views
-1

我是一個非常新的PHP和MySQL。我今天試着在Ubuntu上安裝php,mysql和apache。致命錯誤:調用未定義的函數mysql_connect()

Apache很好,mysql很好,php和安裝很好。但!!當我嘗試編碼:

<?php 
     $link = mysqli_connect('127.0.0.1:80', 'root', 'root'); 
     if (!$link) { 
     die('Could not connect: ' . mysql_error()); 
     } 
     echo 'Connected successfully'; 
     mysql_close($link); 
?> 

我在Firefox的網絡選項卡中有500錯誤。我去error.log,它顯示Call to undefined function mysqli_connect()。我搜索了一整天,得到了解決方案,我必須取消extension=php_mysql.dllextension=php_mysqli.dllextension=php_pdo_mysql.dll

這裏是phpinfo()頁:

MySQL driver for PDO George Schlossnagle, Wez Furlong, Ilia 
MySQL Zeev Suraski, Zak Greant, Georg Richter, Andrey Hristov 
MySQLi Zak Greant, Georg Richter, Andrey Hristov, Ulf Wendel 
MySQLnd  Andrey Hristov, Ulf Wendel, Georg Richter, Johannes Schlüter 

我真的不知道還有什麼地方我錯過了。

任何想法請。

+1

不要使用mysql和mysqli函數進行pick-a-mix –

+1

您是否在啓用擴展後重新啓動apache? – teeyo

+0

如果你是新的更好的學習PDO它更好:http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers – teeyo

回答

0

如果你正在linux上工作,首先檢查php-mysql是否安裝在它上面。

yum install php-mysql 

谷歌apt-get的等價物,如果你使用Ubuntu的。

第二次檢查你的php.ini中的mysql.so。它不應該被評論。

extension=mysql.so 
+0

請不要向新開發者推薦ext/mysql;向他們展示如何安裝mysqli/PDO。 – deceze

+0

extension = mysql.so在php.ini中找不到。我錯過安裝任何東西嗎? – Nothing

+0

@nothing,php和mysql是分開的服務。您需要一個驅動程序來連接這些服務。嘗試apt-get安裝php5-mysql –

0

Warning mysql_query, mysql_fetch_array,mysql_connect etc.. extensions were deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

請勿混用mysql_ *與mysqli_ * extenstion

注:

1)檢查MySQL的安裝是否正確?

2)檢查mysql服務啓動了嗎?

3)安裝mysql後,你有沒有重新啓動你的apche。

 //db connection 

     global $conn; 

     $servername = "localhost"; //host name 

     $username = "username"; //username 

     $password = "password"; //password 

     $mysql_database = "dbname"; //database name 

     //mysqli prepared statement 

     $conn = mysqli_connect($servername, $username, $password) or die("Connection failed: " . mysqli_connect_error()); 

     mysqli_select_db($conn,$mysql_database) or die("Opps some thing went wrong"); 
+0

所以我在php.ini文件中禁用mysql擴展。我可以在mysql shell中使用mysql,這意味着它已經正確安裝。我已經啓動了mysql服務和apache。現在我得到了304錯誤,而不是500。 – Nothing

相關問題