thinkphp連線資料庫

2021-09-08 09:55:11 字數 629 閱讀 4377

首先,建立乙個資料庫thinkphp,在該資料庫裡建立乙個表think_data.

找到配置檔案config.php

新增配置檔案

<?php

return array(

//'配置項'=>'配置值'

'db_type'=>'mysql',

'db_host'=>'localhost',

'db_name'=>'thinkphp',

'db_user'=>'root',

'db_pwd'=>'123',

'db_port'=>'3306',

'db_prefix'=>'think_',

);?>

新增模板資訊,其中volist是用於內建模板引擎輸出資料集的標籤--

最後在控制器中例項化資料庫,輸出資料庫中的資訊。用到了m方法,來連線資料庫

$data=m('data');

$this->data=$data->select();

$this->display();

在瀏覽器中輸入http://localhost/tp/

thinkphp配置連線資料庫技巧

1.在thinkphp入口檔案同目錄下的config.inc.php中新增資料庫程式設計客棧配置資訊 複製 如下 return array db type mysqli db host localhost db name demo db user root db pwd root db prefix...

連線資料庫

2 documents 目錄就是我們可以用來寫入並儲存檔案得地方,一般可通過 nsarray paths nssearchpathfordirectoriesindomains nsdocumentdirectory,nsuserdomainmask,yes nsstring documentsdi...

連線資料庫

1 oracle8 8i 9i資料庫 thin模式 class.forname oracle.jdbc.driver.oracledriver newinstance string url jdbc oracle thin localhost 1521 orcl orcl為資料庫的sid strin...