سؤال

I'm trying to run the following query:

"insert into visits set source = 'http://google.com' and country = 'en' and ref = '1234567890';"

The query looks good to me and it prints a warning:

1 row(s) affected, 2 warning(s): 1364 Field 'country' doesn't have a default value 1292 Truncated incorrect DOUBLE value: 'http://google.com'

And the info isn't stored as expected:

id , ref , bnid, source, country
'5', NULL, NULL, '0'   , ''

If I run the normal syntax like:

insert into visits (source,country,ref) values('http://google.com','en','1234567890');

I get the expected result:

'6', '1234567890', NULL, 'http://google.com', 'en'

The first syntax (insert set) was working in previous server. Now I changed to one with cpanel and it doesn't. It's the second time this week I get this problem in two different VPS with cpanel so I'm guessing it should be the version number or mysql config.

Mysql Version: 5.1.63-cll

Table:

CREATE TABLE `visits` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ref` varchar(64) DEFAULT NULL,
  `bnid` int(11) DEFAULT NULL,
  `source` varchar(256) DEFAULT NULL,
  `country` varchar(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

Any help?

هل كانت مفيدة؟

المحلول

Remove 'and' from the insert query

insert into visits set source = 'http://google.com' , country = 'en' , ref = '1234567890'

نصائح أخرى

When using INSERT...SET, separate the fields using ,, not AND.

INSERT INTO visits SET source = 'http://google.com', country = 'en', ref = '1234567890';
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top