gpt4 book ai didi

php - Codeigniter - MySQL 变量错误

转载 作者:行者123 更新时间:2023-11-29 13:46:57 24 4
gpt4 key购买 nike

当我尝试在 codeigniter 中添加列时,我正确添加了该列,但该值不是变量中的值...

当我定义时:

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

数据库中的硬件 ID:“2147483647”

我不知道为什么......请帮助我!

型号:

<?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);

}
}

最佳答案

您面临“问题”,即您的 ID 大于您的表可以存储的大小,请参阅 here .

INT -2147483648 - 2147483647

要解决此问题,请将您的 bot_hw_id 结构更改为 unsigned,这样可以为您提供更大的“范围”(仅限正值),因为 ID 并不经常出现负值。

(或将其更改为BIGINT)

关于php - Codeigniter - MySQL 变量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17264282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com