![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
上面是一个操作new表的类,都正确.
function connectDatabase()
{
global $db;
if (empty($cDbPointer))
{
$db->connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
if ($this->cEncode=="gb2312") {
$db->Execute("set names `gb2312`");
}
return 1;
}
return 0;
}
/* 关闭数据库连接 */
function closeDatabase()
{
global $db;
$db->close();
}
/*--------------- 数据库基本操作 --------------*/
/* 插入操作 */
function insert($record)
{
global $db;
if(!is_array($record) || count($record) == 0){
return false;
}
if("" == $this->cTableName) return false;
if(0==$this->connectDatabase()) return false;
$rs = $db->Execute("SELECT * FROM {$this->cTableName} WHERE id = -1");
$insertSQL = $db->GetInsertSQL($rs, $record);
if(false==$db->Execute($insertSQL))
{
return $db->ErrorMsg();
}
return $db->insert_ID();
$db->close();
}
//一个表的操作类.
$cmsnew=new Cmsnew;
$record=array();
$record['title']="2434";
$record['author']="我是谁";
$cmsnew->insert($record);
在输入中文的时候
--------------------------------------------------------------------------------
(mysql): set names `gb2312`
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
(mysql): SELECT * FROM topic WHERE id = -1
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
(mysql): INSERT INTO topic ( title, author ) VALUES ( '2434', '我是谁' )
--------------------------------------------------------------------------------
1406: Data too long for column 'author' at row 1
错误.
输入数字的时候就能插入到数据库,这是什么原因?

