Chubby Learn PHP Summary 5-----PHP Operation SQL Database (Deprecated:mysql_connect (): The MySQL extension is Deprecated and would)

Source: Internet
Author: User
Tags deprecated learn php php error

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.