วันอังคารที่ 13 กรกฎาคม พ.ศ. 2553

คำสั่งพื้นฐานจัดการ ฐานข้อมูล MySQL

คำสั่ง ติดต่อฐานข้อมูล

$host="localhost";
$username="root";
$password="14312192";
$db="infor_bms";
$connect=mysql_connect($host,$username,$password) or die ("ไม่สามารถเชื่อมต่อฐานข้อมูลได้");
mysql_db_query($db,"SET NAMES utf8");


คำสั่ง เพิ่มข้อมูล
$sql = "insert into usergroup values('".$username[$i]."','".$group."','1')";
mysql_query($sql);

คำสั่ง แก้ไขข้อมูล
$sql = "update genuser set userlastno = '$last' where userprefix = '$prefix'";
mysql_query($sql);


คำสั่ง ลบข้อมูล
$sql = "DELETE FROM radcheck where UserName = '".$_REQUEST['user']."'";
mysql_query($sql);


ตัวอย่างการแสดงผลข้อมูล

//$sql = "select * from news ";
$sql = "select * from news where user_id='".$_SESSION[userid]."'";
$result = mysql_query($sql);
$num=0;
while($cate = mysql_fetch_object($result)) {
$num++;

//พื้นที่การทำซ้ำเพื่อแสดงผลข้อมูล
$cate->news_photo;

}

ไม่มีความคิดเห็น:

Popular Posts