Home > Backend Development > PHP Tutorial > php菜鸟,thinkphp写数据库有关问题

php菜鸟,thinkphp写数据库有关问题

WBOY
Release: 2016-06-13 12:39:29
Original
992 people have browsed it

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

但是运行后,数据就是添加不进数据库,请各位大侠帮忙看看错在哪里,提前感谢
本人可用分不多,倾囊了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template