TinkPHP访问数据库问题!
ThinkPHP问题:
想实现功能:在mysql中有一张think_form表,字段有id,title,email,content;
通过ThinkPHP连接MySQL test数据库,访问tink_form表中的数据。
实现步骤:
1.定义index.php程序入口
2.在项目中的conf/config.php中添加连接数据库配置信息
'URL_MODEL' => 2, // 如果你的环境不支持PATHINFO 请设置为3
'DB_TYPE' => 'mysql',
'DB_HOST' => 'localhost',
'DB_NAME' => 'test',
'DB_USER' => 'root',
'DB_PWD' => '123456',
'DB_PORT' => '3306',
'DB_PREFIX' => 'think_'
3.创建FormModel.class.php类库
定义 FormModel类继承Model,空实现
4.使用Action对数据进行操作
代码:
public function index(){
header("Content-Type:text/html; charset=utf-8");
// 实例化formmodel
$form = D('Form') ;
$data = $form -> find('id,title'); // 数据为空
echo $data->id ;
$this->display() ;
}
注明: 运行index.php入口文件,框架没有加载conf/config.php文件。