- <?php
- header('Content-Type:text/html; charset=utf-8');
- $conn = @mysqli_connect('127.0.0.1', 'root', '3893527', 'mydatabase_db') or die('資料庫連線失敗'); //資料庫連線(位址, 帳號, 密碼, [資料庫名稱])
- mysqli_query($conn, 'SET NAMES utf8'); //防止亂碼
- /** 查詢 **/
- $sql = "SELECT * FROM `contactinfo_tab`;"; //查詢 contactinfo_tab 資料表
- $result = mysqli_query($conn, $sql); //執行SQL語法
- //echo mysqli_num_rows($result); //查詢資料筆數
-
- /*while($arr_data=mysqli_fetch_assoc($result)){
- //print_r($arr_data);
- //echo '<hr />';
- $ci_birthday = date('Y年m月d日', strtotime($arr_data['ci_birthday'])); //strtotime為轉換成時間戳計
- echo '編號:'.$arr_data['ci_id'].'<br />';
- echo '姓名:'.$arr_data['ci_name'].'<br />';
- echo '生日:'.$arr_data['ci_birthday'].'('.$ci_birthday.')'.'<br />';
- echo '電話:'.$arr_data['ci_tel'].'<br />';
- echo '行動電話:'.$arr_data['ci_mobile'].'<br />';
- echo '通訊地址:'.$arr_data['ci_address'].'<br />';
- echo '建立時間:'.$arr_data['ci_datetime'].'<hr />';
- }*/
- /** 新增 **/
- $sql = "INSERT INTO `contactinfo_tab`(
- `ci_birthday`, `ci_name`, `ci_tel`, `ci_mobile`, `ci_address`, `ci_datetime`
- )VALUES(
- '1987-12-19', 'Steve2', '07-5558897', '0988999888', '三民區', NOW()
- );";
- $result = mysqli_query($conn, $sql); //執行SQL語法
- if($result){
- echo '新增成功!!';
- }else{
- echo '新增失敗!!';
- }
- ?>
複製代碼 |