I was confused, when I figured out that setting value to 0 actually picks some row. O_o
0 is number, not a string…
It’s something i didn’t knew? Some specific feature of mysql or i’m doing something wrong?
Here is query:
SELECT * FROM contacts WHERE owner=0
The result is:
contact_id,owner,contact
10,d9659deb29f21dcf468783f1e7f52aa2b2ab6b48,7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e
Here is test dump:
-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server version: 5.5.8 - Source distribution
-- Server OS: Linux
-- HeidiSQL version: 7.0.0.4053
-- Date/time: 2012-08-02 11:05:48
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;
-- Dumping database structure for test
CREATE DATABASE IF NOT EXISTS `test` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `test`;
-- Dumping structure for table test.contacts
CREATE TABLE IF NOT EXISTS `contacts` (
`contact_id` int(10) NOT NULL AUTO_INCREMENT,
`owner` varchar(40) DEFAULT '',
`contact` varchar(40) DEFAULT '',
PRIMARY KEY (`contact_id`),
KEY `owner` (`owner`),
KEY `contact` (`contact`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
-- Dumping data for table test.contacts: ~2 rows (approximately)
/*!40000 ALTER TABLE `contacts` DISABLE KEYS */;
REPLACE INTO `contacts` (`contact_id`, `owner`, `contact`) VALUES
(9, '7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e', 'd9659deb29f21dcf468783f1e7f52aa2b2ab6b48'),
(10, 'd9659deb29f21dcf468783f1e7f52aa2b2ab6b48', '7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e');
/*!40000 ALTER TABLE `contacts` ENABLE KEYS */;
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
The owner ‘7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e’ is started with a number ‘7…’, MySQL converts this value to 7, we have 7 = 0 – FALSE.
The owner ‘d9659deb29f21dcf468783f1e7f52aa2b2ab6b48’ is started with a char ‘d…’, MySQL converts this value to 0, so 0 = 0 – TRUE.
This is how MySQL converts strings to numbers.