<?php
header("Content-type: text/html; charset=utf-8");
$con = mysql_connect("localhost","sun1227","34808850");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo "数据库连接成功";
mysql_select_db("sun1227");
mysql_query("set names 'utf8'");
$sqlTable="create table userInfo (
id int unsigned not null auto_increment primary key,
userName varchar(5),
tel varchar(11),
sex varchar(1))";
if(mysql_query($sqlTable))
{
echo "恭喜你,数据表创建成功了!";
}
else
{
echo "创建数据表出错,错误号:".mysql_errno()." 错误原因:".mysql_error();
}
$sql = "insert into userinfo(userName,tel,sex) values ('乐磊','17660631583','男')"; //'--'单引号内可以是变量
if(mysql_query($sql))//借SQL语句插入数据
{
echo "恭喜你,表中写入数据成功了!";
}
?>