php連結資料庫

weixin_34290000發表於2018-11-10

index

<?php
include("conn2.php");
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <table border="1px">
            
                <tr>
                    <td>id</td>
                    <td>name</td>
                    <td>pwd</td>
                    <td>type</td>
                </tr>
    <?php
        $result=mysql_query("select*from user");
        while($row=mysql_fetch_assoc($result)){
    ?>
        <tr>
            <td><?php echo $row["id"] ?></td>
            <td><?php echo $row["uname"] ?></td>
            <td><?php echo $row["upwd"] ?></td>
            <td><?php echo $row["utype"] ?></td>
        </tr>
    <?php 
        }
    ?>
        </table>
    </body>
</html>

conn1

<?php
$mysqli=new mysqli("localhost","root","root","hyy");
if($mysqli->connect_errno){
    die("連結錯誤".$mysqli->connect_errno);
}
$mysqli->query("set name utf-8");

$result=$mysqli->query("select*from user");
?>

conn2

<?php
$conn=mysql_connect("localhost","root","root","hyy");
mysql_select_db("hyy",$conn);
mysql_query("set name utf8");
?>

相關文章