The Surrican
The Surrican

Reputation: 29864

Accidentally specified weird sql query. What happened?

I ran this sql query in my database:

update payments set method = 'paysafecard' AND amount = 25 WHERE payment_id IN (1,2,3,4,5,...)

Of course i meant set method = 'paysafecard' , amount = 25

However I did it in phpmyadmin and it showed me that rows were affected. After running it again it showed 0 rows affected.

I don't know what may have changed in the database, what could this have done?

My table looks like this:

CREATE TABLE IF NOT EXISTS `payments` (
  `payment_id` int(11) NOT NULL AUTO_INCREMENT,
  `method_unique_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `method` enum('moneybookers','paypal','admin','wallet','voucher','sofortueberweisung','bitcoin','paysafecard','paymentwall') COLLATE utf8_unicode_ci NOT NULL,
  `method_tid` int(11) DEFAULT NULL,
  `uid` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `plan` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `expires_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `amount` decimal(8,2) NOT NULL,
  `currency` enum('EUR','USD','BTC') COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`payment_id`),
  UNIQUE KEY `method` (`method`,`method_tid`),
  UNIQUE KEY `method_unique_id` (`method_unique_id`,`method`),
  KEY `expires_at` (`expires_at`),
  KEY `uid` (`uid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=8030 ;

I am running -- Server version: 5.1.41 -- PHP Version: 5.3.2-1ubuntu4.11

Upvotes: 1

Views: 124

Answers (1)

jzworkman
jzworkman

Reputation: 2703

This would result in the method field being set to '0' for all of your records fitting the where clause.

It is interpreted as the following:

set method = ('paysafecard' AND amount = 25)

This is a logical AND, and results in a boolean value for these records(which will be parsed to the corresponding field of your column).

Upvotes: 5

Related Questions