New Zenner
- Join Date:
- Dec 2014
- Posts:
- 4
- Plugin Contributions:
- 0
Query returns no results if an id value is selected
I have the following table:
CREATE TABLE IF NOT EXISTS `inventory` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`products_id` INT(11) UNSIGNED DEFAULT NULL,
`options_id` INT(11) UNSIGNED DEFAULT NULL,
`options_values_id` INT(11) UNSIGNED DEFAULT NULL,
`sku` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `products` (`products_id`,`options_id`,`options_values_id`),
UNIQUE KEY `sku` (`sku`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
I'm running the following insert on it:
INSERT INTO inventory (
products_id,
options_id,
options_values_id,
sku
) VALUES (
2,
4,
5,
'K12R-1687'
);
After running this, I can execute mysql_insert_id($db->link) and get the new auto-increment ID. However, if I run the following query right after that within Zen Cart 1.5, I get no results ($result->RecordCount() equals zero):
$result = $db->Execute("SELECT id FROM inventory WHERE sku = 'K12R-1687' LIMIT 1");
If I then copy this query and run it through PHPMyAdmin, I get the id value expected.
If I change the query to this, then it returns the results:
$result = $db->Execute("SELECT id, sku FROM inventory WHERE sku = 'K12R-1687' LIMIT 1");
Of if I change it to this, it finds the products_id but is missing the id naturally:
$result = $db->Execute("SELECT products_id FROM inventory WHERE sku = 'K12R-1687' LIMIT 1");
No queries which get only the id work.
What the heck is going on here?