Home >Database >navicat >How to connect navicat database to php

How to connect navicat database to php

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-08-12 14:39:416140browse

How to connect navicat database to php

The first step is to open Navicat and create a new database.

How to connect navicat database to php

The second step is to create a new table in the database.

How to connect navicat database to php

Related recommendations: "Navicat for mysql graphic tutorial"

The third step is to save the table.

How to connect navicat database to php

The fourth step is to add data to the table.

How to connect navicat database to php

The fifth step is to open the ide, enter the following php code, and use localhost to open the php file.

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

The page displayed in the browser:

How to connect navicat database to php

The above is the detailed content of How to connect navicat database to php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn