开发者

Database contents setting themselves to 0

I have a Database that contains 4 tables, however I'm using 1 of them which is separated from the others.

In this table I have 4 fields which are varchar and the rest are ints (11 other fields), when the users fill up the DB everything gets saved correctly, however it has happened 3 times so far that the database values for the int's reset to 0 without any apparent reason. At first, I thought, it was because those fields (where the numbers should go) were varchars not ints. However since I changed it, it happened again. I've already double checked my code and I have nothing that even updates or inserts a 0 value. Also I'm using codeigniter and active records which protect against SQL injections AND have XSS filtering enabled, could anyone point out something I might be missing or a reason for this to be happening?

Also, I'm pretty sure about the answer of this but, is there ANY way to recover some data?? Other than having to ask everyone to fill in everything again.. =/

** EDIT **

The Storage Engine is MyISAM and Collation is latin1_swedish_ci, Pack Keys are default, for all intents and purposes it's a normal DB

** EDIT **

Here's my Table Structure

-- phpMyAdmin SQL Dump
-- version 3.3.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 10, 2011 at 09:31 AM
-- Server version: 5.0.51
-- PHP Version: 5.2.14

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `cinesdec_prueba`
--

-- --------------------------------------------------------

--
-- Table structure for table `Oscar`
--

CREATE TABLE IF NOT EXISTS `Oscar` (
  `Id` int(20) NOT NULL auto_increment,
  `Nombre` varchar(100) default NULL,
  `ApPaterno` varchar(100) default NULL,
  `ApMaterno` varchar(100) default NULL,
  `Edad` varchar(25) default NULL,
  `Twitter` varchar(250) default NULL,
  `Correo` varchar(250) NOT NULL default '',
  `BestPicture` int(10) unsigned NOT NULL,
  `ActorLead` int(10) unsigned NOT NULL,
  `ActorSupport` int(10) unsigned NOT NULL,
  `ActressLead` int(10) unsigned NOT NULL,
  `ActressSupport` int(10) unsigned NOT NULL,
  `Art` int(10) 开发者_如何学Cunsigned NOT NULL,
  `Directing` int(10) unsigned NOT NULL,
  `Foreing` int(10) unsigned NOT NULL,
  `Music` int(10) unsigned NOT NULL,
  `Visual` int(10) unsigned NOT NULL,
  `Desempate` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`Correo`),
  UNIQUE KEY `Id` (`Id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=89 ;


From what you've described, it sounds like your default value for the fields is 0.

You may have created your table with the defaults in there, like so:

`[column_name]` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'

To remove the default, do the following:

ALTER TABLE `[table_name]` CHANGE `[column_name]` `[column_name]` INT( 10 ) UNSIGNED NOT NULL;

Which will remove the default 0 value (note the removal of DEFAULT '0').

The reason you're seeing the 0s: When the default value is 0, if your INSERT statements don't include the field, MySQL will just insert the default value into the field.

I'm guessing the software you used to create the table automatically added the 0 values, which typically aren't a problem as any related table's id would start at 1 which is the most common value for an integer value.


What SQL_MODE are you using? You need at least STRICT_ALL_TABLES but TRADITIONAL and ANSI might be even better to get a reliable database.

SET SESSION sql_mode='traditional,ansi';
SELECT @@SESSION.sql_mode;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜