Php Fatal Error Call To Undefined Function Mysql_Connect()

     
I am trying lớn do a simple connection with XAMPPhường. and MySQL server, but whenever I try to enter data or connect to lớn the database, I get this error.

Bạn đang xem: Php Fatal Error Call To Undefined Function Mysql_Connect()

Fatal error: Uncaught Error: Điện thoại tư vấn khổng lồ undefined function mysql_connect() in C:xampphtdocs egister.php:22 Staông chồng trace: #0 main thrown in C:xampphtdocs egister.php on line 22

Example of line 22:

$link = mysql_connect($mysql_hostname , $mysql_web1_username);

*

*

mysql_* functions have been removed in PHP.. 7.

You probably have PHP. 7 in XAMPPhường. You now have sầu two alternatives: MySQLi & PDO.

Additionally, here is a nice wiki page about PDO.


*

*

You can use mysqli_connect($mysql_hostname , $mysql_web1_username) instead of mysql_connect($mysql_hostname , $mysql_web1_username).

Xem thêm: Hướng Dẫn Cài Đặt Ubuntu Server 20, Hướng Dẫn Cài Đặt Ubuntu 18

mysql_* functions were removed as of PHP. 7. You now have two alternatives: MySQLi & PDO.


*

It is recommended khổng lồ use either the MySQLi or PDO extensions. It is not recommended to lớn use the old mysql extension for new development, as it was deprecated in PHPhường 5.5.0 & was removed in PHP 7.

PHP offers three different APIs to lớn connect to MySquốc lộ. Below we show the APIs provided by the mysql, mysqli, and PDO extensions. Each code snippet creates a connection to lớn a MySquốc lộ server running on "example.com" using the web1_username "web1_username" & the password "password". And a query is run khổng lồ greet the web1_user.

Example #1 Comparing the three MySquốc lộ APIs

query("SELECT "Hello, dear MySquốc lộ web1_user!" AS _message FROM DUAL");$row = $result->fetch_assoc();emang lại htmlentities($row<"_message">);// PDO$pbởi vì = new PDO("mysql:host=example.com;dbname=database", "web1_username", "password");$statement = $pdo->query("SELECT "Hello, dear MySQL web1_user!" AS _message FROM DUAL");$row = $statement->fetch(PDO::FETCH_ASSOC);emang lại htmlentities($row<"_message">);// mysql$c = mysql_connect("example.com", "web1_username", "password");mysql_select_db("database");$result = mysql_query("SELECT "Hello, dear MySquốc lộ web1_user!" AS _message FROM DUAL");$row = mysql_fetch_assoc($result);emang đến htmlentities($row<"_message">);?>I suggest you try out both MySQLi và PDO & find out what API design you prefer.