Deprecated: mysql_connect()

前端 未结 15 1106
醉酒成梦
醉酒成梦 2020-11-22 06:55

I am getting this warning, but the program still runs correctly.

The MySQL code is showing me a message in PHP:

Deprecated: mysql_connect(): T

相关标签:
15条回答
  • 2020-11-22 07:37

    You can remove the warning by adding a '@' before the mysql_connect.

    @mysql_connect('localhost','root','');
    

    but as the warning is telling you, use mysqli or PDO since the mysql extension will be removed in the future.

    0 讨论(0)
  • 2020-11-22 07:39

    That is because you are using PHP 5.5 or your webserver would have been upgraded to 5.5.0.

    The mysql_* functions has been deprecated as of 5.5.0

    enter image description here

    Source

    0 讨论(0)
  • 2020-11-22 07:39

    PDO class replaces these methods. Example for Mysql or MariaDB :

    $BDD_SQL = new PDO('mysql:host='.BDD_SQL_SERVER.';dbname='.BDD_SQL_BASE.';charset=utf8', 
            BDD_SQL_LOGIN, BDD_SQL_PWD, 
            array(
              PDO::ATTR_EMULATE_PREPARES => false,
              PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //launch exception if error
              PDO::ATTR_DEFAULT_FETCH_MODE=> PDO::FETCH_ASSOC
                    ));
    

    Source : PDO Class

    0 讨论(0)
  • 2020-11-22 07:43

    If you have done your coding then

    ini_set("error_reporting", E_ALL & ~E_DEPRECATED); 
    

    is good option but if you are in beginning then definitely you should use mysqli.

    0 讨论(0)
  • 2020-11-22 07:45

    To suppress the deprecation message for this alone (and stay informed of other deprecations in your code) you can prefix the connect with @:

    <?php
    $connect = @mysql_connect('localhost','root','');
    mysql_select_db('dbname');
    ?> 
    
    0 讨论(0)
  • 2020-11-22 07:46

    mysql_*, is officially deprecated as of PHP v5.5.0 and will be removed in the future.

    Use mysqli_* function or pdo

    Read Oracle Converting to MySQLi

    0 讨论(0)
提交回复
热议问题