刚刚接触PHP,照书本写的例子,这是代码:<?php
$con=mysql_connect("localhost","root","mysql"); //建立连接并赋值给变量
if($con) //如果返回连接标识
{
mysql_select_db("test"); //选择test操作库
$sql="CREATE TABLE temp
(
id int(5) not null auto_increment primary key,
name char(10) not null default '',
sex char(2) not null default '男',
age int(3) not null default 0,
work char(10) not null default '',
city char(10) not null default '',
other char(50) not null default ''
)";
$result=mysql_query($sql); //执行建表SQL语句
if($result) //如果成功执行
{
echo "成功在test数据库中创建表!"; //输出内容
}
else echo "建表时出现错误!".mysql_error();
}
else //如果返回False
{
echo "连接到服务器时出现错误!"; //输出内容
}
?>运行错误是:建表时出现错误!Invalid default value for 'sex'。
我的mysql字符集是:gbk。网上查了很多,没成功,所以发帖求解。该怎么修改代码呢,有想法的都给个提示吧,先谢了!
$con=mysql_connect("localhost","root","mysql"); //建立连接并赋值给变量
if($con) //如果返回连接标识
{
mysql_select_db("test"); //选择test操作库
$sql="CREATE TABLE temp
(
id int(5) not null auto_increment primary key,
name char(10) not null default '',
sex char(2) not null default '男',
age int(3) not null default 0,
work char(10) not null default '',
city char(10) not null default '',
other char(50) not null default ''
)";
$result=mysql_query($sql); //执行建表SQL语句
if($result) //如果成功执行
{
echo "成功在test数据库中创建表!"; //输出内容
}
else echo "建表时出现错误!".mysql_error();
}
else //如果返回False
{
echo "连接到服务器时出现错误!"; //输出内容
}
?>运行错误是:建表时出现错误!Invalid default value for 'sex'。
我的mysql字符集是:gbk。网上查了很多,没成功,所以发帖求解。该怎么修改代码呢,有想法的都给个提示吧,先谢了!
mysql_query("set names gbk");
................在运行试试