mysql 语法

<?php 
// Connect database
$dbhost = '127.0.0.1'; 
$dbuser = 'root'; //我的用户名 
$dbpass = '123456'; //我的密码 
$connect = mysql_connect($dbhost,$dbuser,$dbpass); 

// Create database
if ($connect) { 
echo "非常好,成功了!\n"; 
	mysql_query("CREATE DATABASE my_db",$connect);
} else { 
echo "不好意思,失败了!"; 
} 

// Create table in my_db database

// 检测database
mysql_select_db("my_db");

$sql = "CREATE TABLE Persons 
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";
mysql_query($sql);

// Insert database
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 
VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 
VALUES ('Glenn', 'Quagmire', '33')");


// Select database
$result = mysql_query("SELECT * FROM Persons group by Age");

print_r (mysql_fetch_array($result));

// Update database
mysql_query(" Update Persons set Age = 111 WHERE FirstName ='Peter' ", $connect);


// Close database
mysql_close($connect);
?> 

 

posted @ 2014-04-16 15:57  needly  阅读(176)  评论(0编辑  收藏  举报