欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

怎么在php中使用kohana框架連接數(shù)據(jù)庫

這篇文章將為大家詳細(xì)講解有關(guān)怎么在php中使用kohana框架連接數(shù)據(jù)庫,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比湄潭網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式湄潭網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋湄潭地區(qū)。費(fèi)用合理售后完善,10年實(shí)體公司更值得信賴。

php是什么語言

php,一個嵌套的縮寫名稱,是英文超級文本預(yù)處理語言(PHP:Hypertext Preprocessor)的縮寫。PHP 是一種 HTML 內(nèi)嵌式的語言,PHP與微軟的ASP頗有幾分相似,都是一種在服務(wù)器端執(zhí)行的嵌入HTML文檔的腳本語言,語言的風(fēng)格有類似于C語言,現(xiàn)在被很多的網(wǎng)站編程人員廣泛的運(yùn)用。

1、添加database支持。在kohana\application\bootstrap.php下找到如下段

Kohana::modules(array(
// 'auth'       => MODPATH.'auth',       // Basic authentication
// 'cache'      => MODPATH.'cache',      // Caching with multiple backends
// 'codebench'  => MODPATH.'codebench',  // Benchmarking tool
// 'database'   => MODPATH.'database',   // Database access
// 'image'      => MODPATH.'image',      // Image manipulation
// 'orm'        => MODPATH.'orm',        // Object Relationship Mapping
// 'unittest'   => MODPATH.'unittest',   // Unit testing
// 'userguide'  => MODPATH.'userguide',  // User guide and API documentation
));

去掉database前面的注釋。

2、在kohana\application\config下添加database.conf配置文件,內(nèi)容如下

<?php defined('SYSPATH') or die('No direct access allowed.');
return array
(
    'default' => array
    (
        'type'       => 'MySQL',
        'connection' => array(
            'hostname'   => 'localhost',
            'username'   => 'root',
            'password'   => 'password',
            'persistent' => FALSE,
            'database'   => 'kohanademo',
        ),
        'table_prefix' => '',
        'charset'      => 'utf8',
        'profiling'    => TRUE,
    ),
);
 ?>

修改對應(yīng)的數(shù)據(jù)庫名和密碼就好。

3、在代碼中添加數(shù)據(jù)庫查詢段,kohana\application\classes\controller\user\user.php內(nèi)容修改如下

<?php defined('SYSPATH') or die('No direct script access.');
 
class Controller_User_User extends Controller {
 
public function action_index()
{
$username = Session::instance()->get('username');
$this->response->body('logined:'.$username);
}
 
public function action_login()
{
if($this->request->post())
{
$username = $this->request->post('username');
$password = $this->request->post('password');
 
$query = DB::query(Database::SELECT, "SELECT username FROM user WHERE username=:username AND password=:password");
$query->param(':username', $username);
$query->param(':password', $password);
$user = $query->execute()->current();
if(count($user) > 0)
{
Session::instance()->set('username',$username);
}
$this->request->redirect('/user/user/index');
}
}
}
 ?>

關(guān)于怎么在php中使用kohana框架連接數(shù)據(jù)庫就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

網(wǎng)站欄目:怎么在php中使用kohana框架連接數(shù)據(jù)庫
文章地址:http://chinadenli.net/article28/gsgpjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google關(guān)鍵詞優(yōu)化微信小程序面包屑導(dǎo)航App設(shè)計商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)