ҹ Ŵ Դͼ
(͹ 1) õԴ PHP MySQL 䫷
صҼҹ php programmer ǹФѺ

1. Դ phpmyadmin ѹ localhost ͧ
2. ҧҹŪ myapp_db ѡ tis620_thai_ci
3. ҧ user myapp_user password test123
4. 㹰ҹ myapp_db ҧ table person ˹ 3

id integer(2) ˹ Primary Key Auto Increment
name varchar(255)
age integer(2)

5. ص䫷 C:\web\myapp\
6. ҧ _config.php Code ѧ
<?php
$dbname = "myapp_db";
$dbuser = "myapp_user";
$dbpassword = "test123"; 

$connection = mysql_connect("localhost", $dbuser , $dbpassword);
mysql_select_db($dbname) or die(mysql_error() );
mysql_query("SET NAMES TIS620");
?>
7. ҧ insert.php Code ѧ
<?php
require("_config.php");

extract($_POST);

if ($name !='') {
	$sql="insert into person (name, age) values('$name', '$age') ";
	$result=mysql_query($sql) or die();
}

if ($result) { echo 'OK'; }else{ echo 'Fail'; }
?>
8. ҧ getdata.php Code ѧ
<?php
require("_config.php");

header("content-type: application/x-javascript; charset=TIS-620"); //͡ Ajax  TIS-620

$sql="select * from person order by id ";
$result = mysql_query($sql) or die (mysql_error()); $i=0;
while ($row = mysql_fetch_array($result)) {
	$i++; $name=$row['name']; $age=$row['age'];
	echo "$i : $name ($age )\r\n";
}
?>
© Copyrights 2000 - 2017 www.palthai.com. All rights reserved.