注:數據配置文件的示例文件:thinkphp/conf/convention.php
(1)填寫配置信(配置文件:“./myapp/conf/config.php”):
示例:
<?php
return array(
//'配置項'=>'配置值'
/* 數據庫設置 */
'DB_TYPE' =>
'mysql', // 數據庫類型
'DB_HOST' => 'localhost', // 服務器地址
'DB_NAME' => 'test', // 數據庫名
'DB_USER' => 'root', // 用戶名
'DB_PWD' => '123456', // 密碼
'DB_PORT' => '3306', // 端口
'DB_PREFIX' => 'think_', // 數據庫表前綴
'DB_FIELDTYPE_CHECK' =>
false, // 是否進行字段類型檢查
'DB_FIELDS_CACHE' =>
true, // 啓用字段緩存
'DB_CHARSET' =>
'utf8', // 數據庫編碼默認採用utf8
);
?>
(2)創建表:
CREATE TABLE `think_user` (
`id` int(11) DEFAULT NULL,
`name` varchar(30) DEFAULT NULL,
`pwd` varchar(20) DEFAULT NULL
) ENGINE=InnoDB;
`id` int(11) DEFAULT NULL,
`name` varchar(30) DEFAULT NULL,
`pwd` varchar(20) DEFAULT NULL
) ENGINE=InnoDB;
(3) 執行數據插入操作
在lib/Action下修改IndexAction.class.php文件,內容如下
<?php
class IndexAction extends Action{
function
index(){
public
function index(){
$data=array(
"id"=>"1",
"name="=>"liuning",
"pwd"=>"asd123"
);
M("user")->add($data);
}
}
}
?>