[第四堂] php & sqlite 範例

<form action="" method="post" name="form1″><br>
Input address book data:<br>
<input name="name" type="text" value="shinder"><br>
<input name="phone" type="text" value="0918981520″><br>
<input name="address" type="text" value="Taipei"><br>
<input name="submit" type="submit" value="Add"><br>

<?php

//建立資料連線物件
$pdo = new PDO(“sqlite:mydb.sqlite");

$pdo->exec(“CREATE TABLE address_book (
sid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,
name VARCHAR,
phone VARCHAR,
address VARCHAR,
creation_date DATETIME DEFAULT CURRENT_TIMESTAMP)");
if(count($_POST)>0) {
// 準備新增資料的語法
$name = $_POST[“name"];
$phone = $_POST[“phone"];
$address = $_POST[“address"];
$pdo->exec(“INSERT INTO ‘address_book’ (‘name’, ‘phone’, ‘address’ )
VALUES( ‘$name’, ‘$phone’, ‘$address’)");
}

$pdoStatement = $pdo->prepare(“SELECT * FROM address_book");
$pdoStatement->execute();
$arr;
while($row = $pdoStatement->fetch(PDO::FETCH_ASSOC) ) {
print_r( $row );
}

 

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *