This question already has an answer here:
The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead [duplicate]
                                
                                    (1个答案)
                                
                        
                                4年前关闭。
            
                    
我在端口8080上使用wamp localhost,它可以运行php页面,但是现在我想连接mysql

<table width="200" border="1" dir="rtl">
  <tr>
    <td>Age</td>
    <td>City</td>
    <td>Lname</td>
    <td>Fname</td>
    <td>ID</td>
  </tr>
<?php
mysql_connect("localhost","root","");
mysql_select_db("learnfiles");
$query="select * from users";
$a=mysql_query($query);
while($b=mysql_fetch_assoc($a))
{


     echo "<tr>";
        echo "<td>".$b["age"]."</td>";
        echo "<td>".$b["city"]."</td>";
        echo "<td>".$b["lname"]."</td>";
        echo "<td>".$b["fname"]."</td>";
        echo "<td>".$b["id"]."</td>";
        echo "</tr>";

}
?>


但已弃用错误:mysql_connect():不建议使用mysql扩展,以后将其删除:在第16行的C:\ wamp \ www \ pro \ index.php中使用mysqli或PDO
我将myadmin的端口地址更改为
 [http://localhost:8080/phpmyadmin]
我该如何解决?

最佳答案

使用mysqli代替,因为不推荐使用mysql_connect

$db = new mysqli('localhost', 'user', 'pass', 'DB');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

关于php - 在端口更改时连接mysql ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29454807/

10-11 01:41
查看更多