当前位置 : 主页 > 网络编程 > PHP >

php mysql query

来源:互联网 收集:自由互联 发布时间:2021-07-03
!DOCTYPE htmlhtml head titlemysql test/title /head body ?php $server_ip = '127.0.0.1'; $server_usename = "root"; $server_password = "123"; $conn = mysql_connect($server_ip,$server_usename,$server_password) or die("conn error:".mysql_error()
 
<!DOCTYPE html>
<html>
    <head>
        <title>mysql test</title>
    </head>
    <body>
        <?php
            $server_ip = '127.0.0.1';
            $server_usename = "root";
            $server_password = "123";
            $conn = mysql_connect($server_ip,$server_usename,$server_password) or die("conn error:".mysql_error());
            mysql_select_db("dinning") or die("mysql select db error".mysql_error());
            $result = mysql_query("select * from user");
            $row_num = mysql_num_rows($result);
              
            while($field = mysql_fetch_field($result) ) {
                foreach ($field as $key => $value) {
                    if($key == "name") {
                        echo "$key => $value<br/>";    
                    }
                }
            }
  
            echo "<br/>"."begin"."<br/>";
  
            while($row = mysql_fetch_assoc($result)) {
                foreach ($row as $key => $value) {
                    echo "$key => $value";
                }
                mysql_free_result($result);
                echo "<br/>";
            }
            echo "end"."<br/>";
              
            mysql_close($conn);
        ?>
    </body>
</html>

网友评论