我正在使用codigniter库创建备份" dbutil"我在我的mysql数据库中有字段,当使用下面给出的代码时,它有数据类型位
public function run_backup()
{
$filename="MembersPro_database_$this->curr_date.sql";
$filepath="application/upload/DatabaseBackup/$filename";
$dbfilepath="MembersPro/application/upload/DatabaseBackup/$filename";
$prefs = array(
'ignore' => array(), // List of tables to omit from the backup
'format' => 'sql', // gzip, zip, txt
'filename' =>$filepath, // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
'add_insert' => TRUE,
"foreign_key_checks" =>FALSE
/* 'newline' => "\n",*/
// Newline character used in backup file
);
$backup="CREATE DATABASE IF NOT EXISTS `MembersManagmentSystem`; USE `MembersManagmentSystem` ";
$backup .= $this->dbutil->backup($prefs);
if(!write_file($filepath, $backup))
{
echo "Error";die;
}
else
{
$_SESSION['sucessmsgbackup']="true";
}
$this->insert_into_datbase($filename,$dbfilepath);
redirect("ViewDatabaseBackup");
}
获取错误的输出插入查询
INSERT INTO `User` (`userId`, `userRoleId`,`userActive`, `userIsDelete`) VALUES ('20000046', '20001','1', '0');
在上面给出的查询" userActive"和" userIsDelete"具有数据类型" bit"的字段并且由DbUtil库创建的查询将其视为字符串,因此我在mysql中收到警告错误
"out of range column value"
答案 0 :(得分:1)
Read Here Why you should not use BIT columns in MySQL
查看文件夹并修改核心类,以便它不会逃脱,例如对于mysqli驱动程序
system/database/drivers/mysqli
并找到文件mysqli_utility.php
找到行
$is_int[$i] = in_array(strtolower($field->type),
array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
TRUE);
输入数字
numerics
-------------
BIT: 16
TINYINT: 1
BOOL: 1
SMALLINT: 2
MEDIUMINT: 9
INTEGER: 3
BIGINT: 8
SERIAL: 8
FLOAT: 4
DOUBLE: 5
DECIMAL: 246
NUMERIC: 246
FIXED: 246
并将您的数据类型添加到上面的数组中,如下所示
$is_int[$i] = in_array($field->type,
array(16, 1, 2, 9, 3, 8),
TRUE);