php菜鸟,thinkphp写数据库有关问题
时间:2021-07-01 10:21:17
帮助过:28人阅读
php初学者,thinkphp写数据库问题
配置文件
return array(
'DB_TYPE' => 'mysql',
'DB_HOST' => 'localhost',
'DB_NAME' => 'test',
'DB_USER' => 'root',
'DB_PWD' => '123456',
'DB_PORT' => '3306',
'DB_PREFX' => '',
'DB_FIELDTYPE_CHECK' => false,
'DB_FIELDS_CACHE' => false,
'DB_CHARSET' => 'utf8'
);
控制器类
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index() {
$dataTest = new FirstModel();
$dataTest -> addData();
$name = "hello thinkphp";
$this -> assign($name);
$this -> display();
}
}
?>
模型类
class FirstModel extends Model {
protected $fields = array(
'id', 'cname', 'email', 'indexs', 'btrue', 'created', '_pk'=>'id', '_autoinc'=>true
);
public function addData() {
$data = Array();
$data["cname"] = "aaa";
$data["email"] = "aaa@sina.com";
$data["indexs"] = 1;
$data["btrue"] = 0;
$data["created"] = time();
$first = M('First');
$first -> create($data);
}
}
?>
数据库名称test,数据表名称first
但是运行后,数据就是添加不进数据库,请各位大侠帮忙看看错在哪里,提前感谢
本人可用分不多,倾囊了。