dtxooq1020 2013-06-23 19:08
浏览 50
已采纳

Codeigniter - MySQL变量错误[关闭]

When I try to add a column in codeigniter, I add this column correctly but the value is not the value at the variable...

When I define:

<?php
$hwid = "123893944";
?>

The Hardware-ID in the Database: "2147483647"

I dont know why... Please help me!

Model:

<?php
class Prometheus_model extends CI_Model {

    var $tables = array(
        'bots' => 'bots',
        'users' => 'users'
    );

    function __construct() {
        parent::__construct();
    }

    public function tablename($table = NULL) {
        if(! isset($table)) return FALSE;
        return $this->tables[$table];
    }

    public function insert($table, $data) {
        $this->db->insert($this->tablename($table),$data);
        return $this->db->insert_id();
    }

    public function num_rows($table, $where = NULL) {
        if(isset($where)){
        $this->db->where($where);
        }
        $q = $this->db->get($table);
        return $q->num_rows();
    }

}

?>

Controller:

public function add_bot()
{

    $bot_data = json_decode($this->input->post('bot_data'));

    if($this->prometheus_model->num_rows('bots', array('bot_ip' => $_SERVER['REMOTE_ADDR'])) == 0){

        $to_insert = array(  
           'bot_id' => NULL,
           'bot_add_date' => time(),
           'bot_last_update' => time(), 
           'bot_os' => $bot_data->{'bot_os'},
           'bot_architecture' => $bot_data->{'bot_architecture'},
           'bot_ip' => $_SERVER['REMOTE_ADDR'],
           'bot_port' => $_SERVER['REMOTE_PORT'], 
           'bot_version' => $bot_data->{'bot_version'},
           'bot_name' => $bot_data->{'bot_name'},
           'bot_hw_id' => $bot_data->{'bot_hw_id'}
        );

        echo $to_insert['bot_hw_id']; //HERE IT IS CORRECT, BUT WRONG IN DATABASE! 
        $this->prometheus_model->insert('bots', $to_insert);  

    }
}
  • 写回答

1条回答 默认 最新

  • doulu4534 2013-06-24 09:01
    关注

    You are facing "issue" that your ID is larger than your table can store see here.

    INT -2147483648 - 2147483647

    To solve this please change your bot_hw_id structure to unsigned that gives you even more "range" (in a positive values only), since IDs arent negative so often.

    (Or change it to BIGINT)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建