navicat数据库如何连接php

navicat数据库如何连接php

第一步,打开Navicat,新建数据库。

1565591249(1).png

第二步,在数据库中新建表。

1565591267(1).png

相关推荐:《Navicat for mysql使用图文教程》

第三步,保存表。

1565591282(1).png

第四步,表中添加数据。

1565591294(1).png

第五步,打开ide,输入以下php代码,使用localhost打开该php文件。

<?php
 
    // ip地址、用户名、密码
    $con=mysql_connect("localhost","root","123456");
 
    // 判断是否连接成功
    if(!$con){
        die('数据库连接失败'.mysql_error());
    }else{
        // 设置编码格式
        mysql_query("set name utf8");
 
        // 选择数据库
        mysql_select_db("test",$con);
 
        // 选择数据表
        $result=mysql_query("select * from user");
 
        // 输出表格及th
        echo "<table border='2' width='300'>
                <tr>
                <th>id</th><th>name</th>
                <th>password</th>
                </tr>";
 
        // 遍历数据表中的内容
        while($row=mysql_fetch_array($result)){
            echo "<tr>";
            // userid === 用户id 与数据表中的id名称对应
            echo "<td>".$row['userid']."</td>";
            // username === 用户名称 与数据表中的username名称对应
            echo "<td>".$row['username']."</td>";
            // password === 用户密码 与数据表中的密码对应
            echo "<td>".$row['password']."</td>";
            echo "</tr>";
        }
        echo "</table>";
    }
    // 关闭数据库
    mysql_close($con);
 
?>

浏览器中显示的页面:

1565591308(1).png

以上就是navicat数据库如何连接php的详细内容,更多请关注www.sxiaw.com其它相关文章!