2014-11-06 76 views
0

這是我的第一篇文章here.I是一個android開發人員,我的服務器的東西總是在php中。 我使用基於PHP + codeigniter + MySQL的架構來執行一些基本的數據庫操作,如插入,讀取,更新。 爲了測試腳本功能我射擊,在我的瀏覽器合適的參數腳本網址,但問題是插入功能無法正常工作PHP + Codeigniter + MySQL - >無法執行數據庫操作

URL要火插入 WWW。[XXXXXX]的.com/[ⅩⅩⅩⅩ] /設備/ checkdevice /測試/檢驗/測試

device.php

function checkdevice($did=false) 
     { 
       if($_POST){ 
         $did = $_REQUEST['did']; 
         $name = $_REQUEST['name']; 
         $number = $_REQUEST['number']; 
         $res = $this->device_model->insertid($did, $name, $number); 
         return; 
       } 
     } 

device_model.php

function insertid($id=false,$name=false,$number=false) 
     { 
      $res = $this->db->get_where('tbl_device', array('clm_device_id'=>$id,'clm_device_name'=>$name,'clm_device_number'=>$number))->num_rows; 
      if($res==0){ 
      $date = date("Y-m-d"); 
      $this->db->insert('tbl_device', array('clm_registered'=>$date, 'clm_device_id'=>$id,'clm_device_name'=>$name,'clm_device_number'=>$number)); 
       } 

       return; 
     } 

database.php中//我的數據庫連接工作正常

$active_group = 'default'; 
$active_record = TRUE; 


$db['default']['hostname'] = 'localhost'; 
$db['default']['username'] = 'xxxxx'; 
$db['default']['password'] = 'xxxx'; 
$db['default']['database'] = 'xxxx'; 
$db['default']['dbdriver'] = 'mysql'; 
$db['default']['dbprefix'] = ''; 
$db['default']['pconnect'] = TRUE; //Tried making FALSE but doesnt work 
$db['default']['db_debug'] = TRUE; //Tried making FALSE but doesnt work 
$db['default']['cache_on'] = FALSE; 
$db['default']['cachedir'] = ''; 
$db['default']['char_set'] = 'utf8'; 
$db['default']['dbcollat'] = 'utf8_general_ci'; 
$db['default']['swap_pre'] = ''; 
$db['default']['autoinit'] = TRUE; 
$db['default']['stricton'] = FALSE; 
+0

你什麼錯誤? – 2014-11-06 06:35:02

+0

只是一個空白頁面沒有特定錯誤 – 2014-11-06 06:35:34

+0

嘗試在項目根目錄index.php文件中將'ENVIRONMENT'更改爲'development'。 – 2014-11-06 06:43:57

回答

0

嘗試加載你的模型,並得到直接的函數參數查詢字符串數據,並作出回聲檢查回來後你會得到什麼。

device.php

function checkdevice($did='', $name='', $number='') { 
    echo $did; 
    echo $name; 
    echo $number; 
    // if you get values remove post variable and pass these else try with post vars 
// $did = $this->input->post('did'); 
    //$name = $this->input->post('name'); 
    //$number = $this->input->post('number'); 
    $this->load->model('device_model'); 
    $res = $this->device_model->insertid($did, $name, $number); 
    if($res) { 
    echo 'success'; 
    } 
    else { 
    echo 'fail'; 
    } 
} 

device_model.php

function insertid($id=false,$name=false,$number=false) { 
    $this->db->select('*'); 
    $this->db->where(array('clm_device_id'=>$id,'clm_device_name'=>$name,'clm_device_number'=>$number)); 
    $query = $this->db->get('tbl_device'); 
    if($query->num_rows > 0){ 
    $date = date("Y-m-d"); 
    $this->db->insert('tbl_device', array('clm_registered'=>$date, 'clm_device_id'=>$id,'clm_device_name'=>$name,'clm_device_number'=>$number)); 
    return $this->db->insert_id(); 
    } 
    else{ 
    return false ; 
    } 
} 
+0

現在添加您的代碼並激髮網址顯示 - > 404未找到頁面 找不到您請求的頁面。 – 2014-11-06 06:54:42

+0

檢查更新請確保你有$ did,$ name等在函數中的值嘗試與一個cho – 2014-11-06 07:00:56

+0

@RakeshSharma我認爲你需要改變'checkdevice($ arg1,$ arg2,$ arg3)'並刪除$ this-> input - >後。 – 2014-11-06 07:04:32