PHP向MySql中插入資料

來源:互聯網
上載者:User

標籤:

<!DOCTYPE html><!--To change this license header, choose License Headers in Project Properties.To change this template file, choose Tools | Templatesand open the template in the editor.--><html>    <head>        <meta charset="UTF-8">        <title>Yosha‘s PHP</title>    </head>    <body>        <?php        $servername = "localhost";        $username = "yosha";        $password = "leon0924";        $dbname = "test";// 建立串連        $conn = new mysqli($servername, $username, $password, $dbname);// 檢測串連        if ($conn->connect_error) {            die("串連失敗: " . $conn->connect_error);        } /////資料插入操作        $sql3 = "INSERT INTO student(SID,Name,Age) values(‘B23‘,‘Yosha‘,‘22‘)";        if ($conn->query($sql3) === TRUE) {            echo "新記錄插入成功";        }         else {           echo "Error: " . $sql3 . "<br>" . $conn->error;        }       // $sql2= "INSERT INTO student(SID,Name,Age) VALUES(‘B23‘,‘Yosha‘,22)";        $sql = "SELECT * FROM student";        $result = $conn->query($sql);        if ($result->num_rows > 0) {            // 輸出每行資料                        while ($row = $result->fetch_assoc()) {                echo "<br> 學號: " . $row["SID"] . " 姓名: " . $row["Name"] . " 年齡:" . $row["Age"];                            }                    } else {            echo "0 個結果";        }        $conn->close();        ?>     </body></html>

  像student表中插入一條資料

PHP向MySql中插入資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.