How to solve Mysql to mysql as I have some problem

2019-09-24 09:36发布

问题:

This question already has an answer here:

  • Why shouldn't I use mysql_* functions in PHP? 16 answers

Th problem: it says

Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Applications/XAMPP/xamppfiles/htdocs/...

I think I have change mysql to mysql but how?

<?php

    $database="sphider_db";
    $mysql_user = "root";
    $mysql_password = ""; 
    $mysql_host = "localhost";
    $mysql_table_prefix = "";



    $success = mysql_pconnect ($mysql_host, $mysql_user, $mysql_password);
    if (!$success)
        die ("<b>Cannot connect to database, check if username, password and host are correct.</b>");
    $success = mysql_select_db ($database);
    if (!$success) {
        print "<b>Cannot choose database, check if database name is correct.";
        die();
    }
?>

回答1:

MySQL extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

Use MySQLi-connect insted of MySQL_connect
as well as instead of mysql_select_db use mysqli_select_db


EDIT 01

in mysqli_connect you can select database too

$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");


回答2:

You have to stop using mysql_* functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy.