I don't wan't to prepare or bind params, I just want to simply execute the call to the procedure, which is stored in my restaurant database. The procedure receives 2 input parameters that I need to pass in via variables that I got from the AJAX script. When I call the procedure from Workbench, it works perfectly, but will not work when called from PHP script.
<?php
//Open Database Connection
$connection = "mysql:host=localhost;dbname=restaurant";
$user = "root";
$pwd = "Dumpweed37!";
$db = new PDO($connection, $user, $pwd);
//Get variables from AJAX
$first = $_GET["first"];
$last = $_GET["last"];
$type = $_GET["type"];
//Add new employee
if ($type==="server"){
$add = $db->exec('CALL AddServer($first, $last)'); }
else if ($type==="bartender"){
$add = $db->exec('CALL AddBartender($first, $last)'); }
else if ($type==="host"){
$add = $db->exec('CALL AddHost($first, $last)'); }
Here is my stored procedures:
DROP PROCEDURE IF EXISTS AddServer$$
CREATE PROCEDURE AddServer(firstname TEXT,lastname TEXT)
BEGIN
INSERT INTO employee VALUE (NULL, firstname,lastname);
INSERT INTO server VALUE (LAST_INSERT_ID(), NULL);
END$$
DROP PROCEDURE IF EXISTS AddBartender$$
CREATE PROCEDURE AddBartender(firstname TEXT,lastname TEXT)
BEGIN
INSERT INTO employee VALUE (NULL, firstname,lastname);
INSERT INTO bartender VALUE (LAST_INSERT_ID());
END$$
DROP PROCEDURE IF EXISTS AddHost$$
CREATE PROCEDURE AddHost(firstname TEXT,lastname TEXT)
BEGIN
INSERT INTO employee VALUE (NULL, firstname,lastname);
INSERT INTO `host` VALUE (LAST_INSERT_ID());
END$$