info.php

作者: 运维开发_西瓜甜 | 来源:发表于2020-08-31 15:25 被阅读0次

    本文链接: https://www.jianshu.com/p/ef3c201441f1

    <!DOCTYPE html>
    <html>
    <head>
            <title>PHP 动态网站</title>
    </head>
    <body>
      <?php
            $user_name = 'shark';
            echo "<h1>".$user_name."</h1>";
      ?>
      <img src="/test.jpg" >
    </body>
    </html>
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>PHP 动态网站</title>
    </head>
    <body>
        <h1>学员信息表</h1>
        <table>
            <thead>
                <tr><th> 序号</th><th>姓名</th><th> 年龄</th></tr>
            </thead>
            <tbody>
                <?php
                    define('DB_HOST', '172.17.0.2');
                    define('DB_USER', 'shark');
                    define('DB_PASS', 'QFedu123!');
                    define('DB_NAME', 'shark_db');
    
                    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
                    $query = "select id,name,age from t1 where name=%s;";
                    $result = mysqli_query($dbc, $query);
    
                    while ($row = mysqli_fetch_array($result)) {
                        $user_id = $row['id'];
                        $user_name = $row['name'];
                        $user_age = $row['age'];
    
                        echo "<tr>";
                        echo "<td>".$user_id."</td>";
                        echo "<td>".$user_name."</td>";
                        echo "<td>".$user_age."</td>";
                        echo "</tr>";
                    }
    
                ?>
            </tbody>
        </table>
    
    </body>
    </html>
    
    

    在 php 语言中使用英文的 . 连接字符串和变量
    echo "<h1>".DB_USER."</h1>" ,其中 DB_USER 是使用 define() 定义的变量。

    相关文章

      网友评论

          本文标题:info.php

          本文链接:https://www.haomeiwen.com/subject/euwgnhtx.html