[第九週] 從 PHP 連線到 MySQL 資料庫


  1. 新增一個專用來連線的 php 檔案

    <?php
    $server_name = 'localhost';
    $username = 'pikaju';
    $password = '1234';
    $db_name = 'pikaju';  
    $conn = new mysqli($server_name, $username, $password, $db_name);
     if($conn->connect_error) {
          die('資料庫連線錯誤:' . $conn->connect_error);
     }
    ?>
    
  2. 在data.php的檔案 引入連線的 php

    <?php
    require_once ('conn.php');
     if (empty($_POST['name']) || empty($_POST['age'])) {
         echo "請確認資料無誤<br>";
         exit();
     }
     echo "Hello " . $_POST['name'] .'<br>';
     echo "Your age is " . $_POST['age'] . '<br>';
    ?>
    






Related Posts

[Week 2] JavaScript - 判斷式、迴圈

[Week 2] JavaScript - 判斷式、迴圈

Robotframework框架介紹

Robotframework框架介紹

MTR04_0706

MTR04_0706



Sponsored



Comments