Jump to content

[SOLVED] 'mysql_query' not inserting data properly...


eco

Recommended Posts

The insert of my data into a table fails on a single column but why?!?

 

Here is where the problem but I just can't figure it out:

    public function InsertBackupStatus($sqlArray)
    {
        self::ConnectToDatabase();

        foreach($sqlArray as $nest)
        {
            for($i = 0;$i < count($nest);$i+=5)
            {
                $this->_sql = "INSERT INTO tbl_backuplog (`id_bkuplog`,`group`,`login`,`date`,`bkupid`,`status`) VALUES('',\"" . $nest[$i] . "\",\"" . $nest[$i+1] . "\",\"" . $nest[$i+2] . "\",\"" . $nest[$i+3] . "\",\"" . $nest[$i+4] . "\");";
                echo "$this->_sql\n";

                $result = mysql_query($this->_sql);
                if (! $result) {
                    $message = 'Invalid query: ' . mysql_error() . "\n";
                    $message .= 'Whole query: ' . $query;
                    die($message);
                }
            } //for
        } //foreach
        self::DisconnectFromDatabase();
    }

 

What echo "$this->_sql\n"; returns:

INSERT INTO tbl_backuplog (`id_bkuplog`,`group`,`login`,`date`,`bkupid`,`status`) VALUES('',"SDE","seniorie","2009-06-13","1218004439609","SUCCESS");
INSERT INTO tbl_backuplog (`id_bkuplog`,`group`,`login`,`date`,`bkupid`,`status`) VALUES('',"SDE","seniorie","2009-06-13","1218875528328","SUCCESS");
INSERT INTO tbl_backuplog (`id_bkuplog`,`group`,`login`,`date`,`bkupid`,`status`) VALUES('',"SDE","seniorie","2009-06-13","1216242642656","SUCCESS");

 

What the database returns is:

+------------+----------------+-------------+---------------------+------------+-----------------------+
| id_bkuplog | group          | login       | date                | bkupid     | status                |
+------------+----------------+-------------+---------------------+------------+-----------------------+
|     000024 | SDE            | seniorie    | 2009-06-13 00:00:00 | 2147483647 | SUCCESS       |
|     000025 | SDE            | seniorie    | 2009-06-13 00:00:00 | 2147483647 | SUCCESS       |
|     000026 | SDE            | seniorie    | 2009-06-13 00:00:00 | 2147483647 | SUCCESS       |
+------------+----------------+-------------+---------------------+------------+-----------------------+

 

Note how all fields are correct except for the db column bkupid where all ids are the same.

 

How can that be when an echo of the SQL query before hand shows the right data.

 

Table structure:

DROP TABLE IF EXISTS `tbl_backuplog`;

SET @saved_cs_client    = @@character_set_client;

SET character_set_client = utf8;

CREATE TABLE `tbl_backuplog` (

  `id_bkuplog` int(6) unsigned zerofill NOT NULL auto_increment COMMENT 'Backup log ID',
  `group` varchar(30) NOT NULL,
  `login` varchar(30) NOT NULL,
  `date` datetime NOT NULL COMMENT 'Backup date',
  `bkupid` int(13) NOT NULL,
  `status` varchar(30),
  PRIMARY KEY  (`id_bkuplog`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='table';
SET character_set_client = @saved_cs_client;

 

Does anyone have a clue?

 

Thanks

-eco

You are attempting to put a value into an integer that is larger than what an integer can hold. There is no such thing as INT(13). INT(11) is the most an integer will display.

 

INT[(M)] [uNSIGNED] [ZEROFILL]

 

A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295

 

If those values are in fact numbers, you would need to use BIGINT. If they are identifying strings (which is how you are treating them in the query, as strings), then you should be using a VARCHAR data type.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.