PHP+代码点火器+MySQL->;无法执行数据库操作


PHP + Codeigniter + MySQL -> unable to perform db operations

这是我在这里的第一篇文章。我是一名安卓开发人员,我的服务器总是在php中。我使用PHP+代码点火器+基于MySQL的架构来执行一些基本的数据库操作,如插入、读取、更新。为了测试脚本的功能,我在浏览器中使用正确的参数启动脚本url,但问题是插入功能不起作用

为插入而激发的URLwww。[xxxxxx].com/[xxxx]/device/checkdevice/test/test/test

设备.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;

尝试加载您的模型,并直接在函数参数中获取查询字符串数据,并在返回后进行回声检查。

设备.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 ;
  }
}