yii-1.1.7.r3135
Windows server
I run this code and get an update view+=2 instead of view+=1…
$page = Page::model()->findByPk($this->id);
$page->views++;
$page->save(false, array('views'));
What am I doing wrong?
yii-1.1.7.r3135
Windows server
I run this code and get an update view+=2 instead of view+=1…
$page = Page::model()->findByPk($this->id);
$page->views++;
$page->save(false, array('views'));
What am I doing wrong?
Where do you see the wrong incrementation? On the page or during debug?
If the first, be careful! The method can be call two time without your notice.
Hope this help
Angelo
I run the code, look at the table in phpMyAdmin and see an incorrect increment…
I think that this bug PDO in Win PHP 5.3.3! This code repeats the problem…
$pdo = new PDO('mysql:host=localhost;dbname=idea', 'root', '');
$statement = $pdo->prepare('UPDATE iea_page SET views=:yp0 WHERE id=1');
$statement->bindValue(':yp0', 10); //Set views = 10
$statement->execute(); // !!! Set views = 11
Test table…
CREATE TABLE IF NOT EXISTS `iea_page` (
`id` int(10) unsigned NOT NULL,
`content` text NOT NULL,
`views` int(10) unsigned NOT NULL DEFAULT '0',
`publish` tinyint(1) unsigned NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `iea_page`
--
INSERT INTO `iea_page` (`id`, `content`, `views`, `publish`) VALUES
(1, 'Text', 131, 1);
napeHeK
Have you reported it to PDO team?
No, I don’t know where send this report…
Works again.
Checked your script locally in 5.3.6 and it works just fine inserting 10.
Test at home server
$model = ResumeConfig::model()->findByPk(1);
$model->active++;
$model->save(false,array('active'));
CREATE TABLE IF NOT EXISTS `resume_config` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_user` int(11) DEFAULT NULL,
`notshow_career` tinyint(1) DEFAULT '0',
`notshow_education` tinyint(1) DEFAULT '0',
`active` int(1) unsigned DEFAULT '0',
`created_at` datetime DEFAULT NULL,
`hot` tinyint(1) DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
work fine;
PHP Version 5.3.1
Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
MySQL- 5.1.41
maybe you have some mysql triggers???