创建库
$con = mysql_connect("localhost:3306","root","root");
mysql_query("CREATE DATABASE my_db",$con)
创建表
CREATE TABLE IF NOT EXISTS 'wx_user'(
'id' int(7) NOT NULL AUTO_INCREMENT,
'openid' varchar(30) NOT NULL,
'username' varchar(20) NOT NULL,
'telphone' varchar(16) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE KEY 'openid' ('openid')
) ENGINE=MyISAN DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
插入数据
$con = mysql_connect("localhost:3306","root","root");
mysql_query("SET NAMES 'UTF8'");
mysql_select_db("book",$con);
mysql_query("INSERT INTO 'wx_user' ('id','openid','username','telphone') VALUES (NULL,'FJDAKFJAFDFA','李四','1379*****42') ");
mysql_close($con);
更新数据
$con = mysql_connect("localhost:3306","root","root");
mysql_query("SET NAMES 'UTF8'");
mysql_select_db("book",$con);
$result = mysql_query("UPDATE 'wx_user' SET 'telphone' = '1369*****32' WHERE 'openid' = 'FJDAKFJAFDFA';");
mysql_close($con);
查询数据
$con = mysql_connect("localhost:3306","root","root");
mysql_query("SET NAMES 'UTF8'");
mysql_select_db("book",$con);
$result = mysql_query("SELECT * FROM 'wx_user' WHERE 'openid' = 'FJDAKFJAFDFA' ");
while($row = mysql_fetch_arrary($result)){
echo $row['username']." ".$row['telphone'];
echo "
";
}
mysql_close($con);
删除数据
$con = mysql_connect("localhost:3306","root","root");
mysql_query("SET NAMES 'UTF8'");
mysql_select_db("book",$con);
mysql_query("DELETE FROM 'wx_user' WHERE 'openid' = 'FJDAKFJAFDFA'")
mysql_close($con);