First: Open the database
To operate the SQL database, you must first establish a connection to the MySQL server and connect to the MySQL server statement:
mysql_connect (' hostname ', ' username ', ' password ')
The return value of the function is used to indicate that the database connection succeeds, and if the connection succeeds, it returns a resource to prepare for subsequent SQL instructions.
<?php$link = mysql_connect ("localhost:3306", "root", "123456") or Die ("Cannot connect to the database server, the database service may not start or the user name password is wrong!"); if ($link) {echo "Database connection succeeded! ";}? >
Second: An error occurred (warning)
However, when I was testing, I would have this situation:Deprecated:mysql_connect (): The MySQL extension is Deprecated and will being removed in the future: Use mysqli or PDO instead in the bottom shows that the database connection was successful. What's wrong with that?
Third: Causes and Solutions php 5 version, 5.2, 5.3, 5.4, 5.5, afraid to keep up with the times, the new server directly on the 5.5, but the program appears the following error: Deprecated:mysql_connect (): the MySQL Extension are deprecated and will being removed in the Future:use mysqli or PDO instead in, see the meaning is very clear, said mysql_connect This module will be deprecated in the future, please You can use MYSQLI or PDO instead. Workaround 1:
Prohibit PHP error
Display_errors = on change to display_errors = Off
Since this server is for users, sometimes they need to make an error (...). Are for friends, ^_^), can not do this, let them change the procedure, see the second program.
Workaround 2:
Common PHP syntax to connect MySQL is as follows
<?php$link = mysql_connect (' localhost ', ' user ', ' password '); mysql_select_db (' dbname ', $link); Change to Mysqi<?php$link = Mysqli_connect (' localhost ', ' user ', ' password ', ' dbname ');
MySQL is commonly used to build table SQL as follows
<?php// old mysql_query (' Create temporary table ' table ', $link);//New Mysqli_query ($link, ' create temporary table ' table ');
Workaround Three:
Set the alarm level in the PHP program code
Error_reporting (e_all ^ e_deprecated);
Welcome everybody to exchange study together, O (∩_∩) o hahaha ~
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Chubby Learn PHP Summary 5-----PHP Operation SQL Database (Deprecated:mysql_connect (): The MySQL extension is Deprecated and would)