I'm using PDO to call a stored procedure that starts with a DROP TABLE IF EXISTS. I'm randomly getting PDOException 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'historygr.reached' doesn't exist' and even more annoying it'll go from telling me that to throwing an exception saying that the table already exists, within a matter of seconds of each other, seemingly from the same connection.
I can't trigger the error myself, but I get error notifications of it.
Here's the PHP that the errors originate in:
$dbh = PDODB::getInstance();
$stmt = $dbh->query("CALL ListReached(".$this->item_id.")"); // <-- ERROR
$items = $stmt->fetchAll();
And here's the MySQL Procedure definition:
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ListReached`( IN root INT)
BEGIN
DECLARE rows SMALLINT DEFAULT 0;
DROP TABLE IF EXISTS reached;
CREATE TABLE reached(
node_id INT PRIMARY KEY
) ENGINE=HEAP;
INSERT INTO reached VALUES (root);
SET rows = ROW_COUNT();
WHILE rows > 0 DO
INSERT IGNORE INTO reached
SELECT DISTINCT child_id
FROM related_item AS r
INNER JOIN reached AS p ON r.parent_id = p.node_id;
SET rows = ROW_COUNT();
INSERT IGNORE INTO reached
SELECT DISTINCT parent_id
FROM related_item AS r
INNER JOIN reached AS p ON r.child_id = p.node_id;
SET rows = rows + ROW_COUNT();
END WHILE;
DELETE FROM reached WHERE node_id = root;
SELECT * FROM reached;
DROP TABLE reached;
END