當前位置:九游会j9娱乐平台-九游ag登录中心网址 » 操作系統 » ci資料庫連接

ci資料庫連接-九游会j9娱乐平台

發布時間: 2024-07-15 20:25:47

1. ci框架裡面怎麼導出資料庫的數據到excel文件

首先我們使用sqlyogent工具,連接到mysql資料庫。
連接成功後在左側的目錄位置,找到需要的表,右鍵打開表
也可以直接在sql執行器中輸入:
select
*
from
datetable
name
打開這個表在sql執行器的下方,結果下方,最左側的位置,如下圖,有一個小圖標,滑鼠移動上面會浮出文字「導出為....」點擊這個圖標點擊後會彈出一個名為「導出為」的彈出窗口,選擇需要導出的文件格式:如csv、html、xnl等,在右側選擇導出的欄位在界面的最下方有一個輸入框,框中是程序默認的一個導出的路徑,也可以點擊路徑旁的按鈕,進行自定義導出文件路徑。

2. ci框架中如何連接兩個資料庫,一個是本地的資料庫,一個是遠程的,我要同時操作兩個資料庫

ci手冊中貌似無法設置兩個資料庫,我遇到這樣的問題都是遠程資料庫有個介面地址。然後訪問它來取得遠程數據的。

3. php ci框架修改數據的方法

ci框架下的php增刪改查總結:
controllers下的 cquery.php文件
[php] view plain

class cquery extends controller {

//構造函數
function cquery() {
parent::controller();
// $this->load->database();

}

function index() {
//調用model 其中train為外層文件夾 mquery為model名稱 querylist為重命名
$this->load->model('train/mquery','querylist');
//獲得返回的結果集 這里確定調用model中的哪個方法
$result = $this->querylist->querylist();
//將結果集賦給res
$this->smarty->assign('res',$result);
//跳轉到顯示頁面
$this->smarty->view('train/vquery.tpl');
}

//進入新增頁面
function addpage() {
$this->smarty->view('train/addpage.tpl');
}

//新增
function add() {
//獲得前台數據
//用戶名
$membername = $this->input->post('membername');
//密碼
$password = $this->input->post('password');
//真實姓名
$userrealname = $this->input->post('userrealname');
//性別
$sex = $this->input->post('sex');
//出生日期
$bornday = $this->input->post('bornday');
//e_mail
$email = $this->input->post('email');
//密碼問題
$question = $this->input->post('question');
//密碼答案
$answer = $this->input->post('answer');
//調用model
$this->load->model('train/mquery','addrecord');
//向model中的addrecord傳值
$result = $this->addrecord->addrecord($membername,$password,$userrealname,$sex,$bornday,$email,$question,$answer);
//判斷返回的結果,如果返回true,則調用本頁的index方法,不要寫 $result == false 因為返回的值未必是false 也有可能是""
if ($result) {
$this->index();
} else {
echo "add failed.";
}
}
//刪除
function deletepage() {
//獲得id
$deleteid = $this->uri->segment(4);
//調用model
$this->load->model('train/mquery','delrecord');
//將值傳入到model的delrecord方法中
$result = $this->delrecord->delrecord($deleteid);
//判斷返回值
if ($result) {
$this->index();
} else {
echo "delect failed.";
}
}
//修改先查詢
function changepage() {
$changeid = $this->uri->segment(4);
$this->load->model('train/mquery','changerecord');
$result = $this->changerecord->changerecord($changeid);
//將結果集賦給res
$this->smarty->assign('res',$result);

//跳轉到顯示頁面
$this->smarty->view('train/changepage.tpl');
}
//修改
function change() {
//獲得前台數據
//id
$id = $this->input->post('id');
//用戶名
$membername = $this->input->post('membername');
//密碼
$password = $this->input->post('password');
//真實姓名
$userrealname = $this->input->post('userrealname');
//性別
$sex = $this->input->post('sex');
//出生日期
$bornday = $this->input->post('bornday');
//e_mail
$email = $this->input->post('email');
//密碼問題
$question = $this->input->post('question');
//密碼答案
$answer = $this->input->post('answer');
//調用model
$this->load->model('train/mquery','change');
//向model中的change傳值
$result = $this->change->change($id,$membername,$password,$userrealname,$sex,$bornday,$email,$question,$answer);
//判斷返回的結果,如果返回true,則調用本頁的index方法,不要寫 $result == false 因為返回的值未必是false 也有可能是""
if ($result) {
$this->index();
} else {
echo "change failed.";
}
}
}
models中的 mquery.php 文件
[php] view plain

class mquery extends model {
//構造函數
function mquery() {
parent::model();
//連接資料庫
$this->load->database();
}

//查詢列表
function querylist() {
//防止select出的數據存在亂碼問題
//mysql_query("set names gbk");
//sql語句
$sql = "select id,member_name,sex,e_mail from user_info_t";
//執行sql
$rs = $this->db->query($sql);
//將查詢結果放入到結果集中
$result = $rs->result();
//關閉資料庫
$this->db->close();
//將結果集返回
return $result;
}

//新增
function addrecord($membername,$password,$userrealname,$sex,$bornday,$email,$question,$answer) {
//防止select出的數據存在亂碼問題
//mysql_query("set names gbk");
//sql語句
$sql = "insert into user_info_t (member_name,password,user_real_name,sex,born_day,e_mail,question,answer) " .
"values ('$membername','$password','$userrealname','$sex','$bornday','$email','$question','$answer')";
//執行sql
$result = $this->db->query($sql);
//關閉資料庫
$this->db->close();
//返回值
return $result;
}

//刪除
function delrecord($deleteid) {
//防止select出的數據存在亂碼問題
//mysql_query("set names gbk");
$sql = "delete from user_info_t where id = $deleteid";
$result = $this->db->query($sql);
$this->db->close();
return $result;
}

//修改前查詢
function changerecord($changeid) {
//防止select出的數據存在亂碼問題
//mysql_query("set names gbk");
$sql = "select id,member_name,password,user_real_name,sex,born_day,e_mail,question,answer from user_info_t where id = $changeid";
//執行sql
$rs = $this->db->query($sql);
$result = $rs->row();//$result = $rs[0]
//關閉資料庫
$this->db->close();
//將結果集返回
return $result;
}

//修改
function change($id,$membername,$password,$userrealname,$sex,$bornday,$email,$question,$answer) {
//防止select出的數據存在亂碼問題
//mysql_query("set names gbk");
//sql語句
$sql = "update user_info_t set member_name = '$membername',password = '$password', user_real_name = '$userrealname'," .
"sex = '$sex',born_day = '$bornday',e_mail = '$email',question = '$question',answer = '$answer'" .
"where id = $id";
//執行sql
$result = $this->db->query($sql);
//關閉資料庫
$this->db->close();
//返回值
return $result;
}
}

views 下的 addpage.tpl文件

[php] view plain







































用戶名
密碼
真實姓名
性別
出生日期
e_mail
密碼問題
密碼答案








4. ci框架如何在控制器裡面鏈接資料庫.然後執行sql語句

在conf的自動載入,開啟database自動載入,配置好資料庫賬號密碼等,然後在控制器中如下:
$userinfo = $this->db->get('user'); //user為user表名
或者
$query = "select * from user";
$this->db->query($query);

熱點內容
matlab命令窗口和新建腳本 發布:2024-07-17 15:51:26 瀏覽:374
建ftp文件夾 發布:2024-07-17 15:51:26 瀏覽:954
魔獸撿物腳本 發布:2024-07-17 15:27:56 瀏覽:129
開發ip伺服器 發布:2024-07-17 15:24:42 瀏覽:387
安卓系統視頻製作哪個好用 發布:2024-07-17 15:10:47 瀏覽:210
androidapk結構 發布:2024-07-17 15:10:43 瀏覽:945
c語言指針的例子 發布:2024-07-17 15:08:01 瀏覽:768
linuxzcat 發布:2024-07-17 15:02:09 瀏覽:901
賓士編程嗎 發布:2024-07-17 14:57:08 瀏覽:853
硬碟加密硬體 發布:2024-07-17 14:51:05 瀏覽:836
网站地图