[第九週] 從 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

MTR04_0620

MTR04_0620

Day03 : 字典、集合

Day03 : 字典、集合

Todo list_Part1:前端功能

Todo list_Part1:前端功能




Sponsored



Comments