这是我在这里的第一篇文章。我是一个Android开发人员,我的服务器东西总是在php。 我使用PHP + codeigniter +基于MySQL的架构来执行一些基本的数据库操作,如插入,读取,更新。 为了测试脚本功能,我在浏览器中使用适当的参数触发脚本url,但问题是插入功能不起作用
URL要触发插入 的 万维网。[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 :(得分: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 ;
}
}