[MySQL] mysql_connect (): The MySQL extension is deprecated and would be a removed in the Future:use mysqli or PDO instead in

Source: Internet
Author: User
Tags deprecated php error

from:http://www.ttlsa.com/php/deprecated-mysql-connect/

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 is Deprecated And will is 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 use MYSQLI or PDO instead.

Workaround 1:

Prohibit PHP error

display_errors = On
改为
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 program bar, see Program 2.

Workaround 2:

Common PHP syntax to connect MySQL is as follows

<?php
$link= mysql_connect(‘localhost‘, ‘user‘, ‘password‘);
mysql_select_db(‘dbname‘, $link);
改成mysqi
<?php
$link= mysqli_connect(‘localhost‘, ‘user‘, ‘password‘, ‘dbname‘);

MySQL is commonly used to build table SQL as follows

<?php
//  老的
mysql_query(‘CREATE TEMPORARY TABLE `table`‘, $link);
// 新的
mysqli_query($link, ‘CREATE TEMPORARY TABLE `table`‘);
Workaround Three:

Set the alarm level in the PHP program code

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

Deprecated's problem is solved, but it is recommended that you cancel the use of MySQL as soon as possible, all toward mysqli or Mysqlnd and so on. MySQL is really too insecure and too old.

========================================= Complete Test Examples:
<?php//method One: The old method function Test1 () {$con = mysql_connect ("localhost", "root", "123456"), if (! $con) {die (' Could not Connect: '. Mysql_error ());} Elseecho "Open MySQL db success<br/>"; Mysql_close ($con);} Test1 ();//Method Two: New method echo "test2<br>"; function Test2 () {$link = Mysqli_connect ("localhost", "root", "123456", ""); if (! $link) {die (' Could not connect: '. Mysql_error ());} Elseecho "Open MySQL db success<br/>"; Mysqli_close ($link);} Test2 ();? >

Operation Result:

Deprecated:mysql_connect (): The MySQL extension is Deprecated and would be a removed in the Future:use mysqli or PDO Instea D in/users/zcm/work/pocketmu/source/vn/vn0/web/mu/th/t1.php on line 6Open MySQL db successtest2open MySQL db success

[MySQL] mysql_connect (): The MySQL extension is deprecated and would be a removed in the Future:use mysqli or PDO instead in

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.