I would like to ask why is this query unable to create the Procedure from the .php file upon execution from a link ? So far the queries works within the SQL as shown here: Original Code Here
**Update I am able to execute the query 1-3 but not 0 and 4.
It's not able to run query0 to drop the database to make a new one and also unable to CALL the Procedure ...
<?php
function Connection(){
$server="SERVER";
$user="ADmin";
$pass="password";
$db="Apex";
$query0= " DROP DATABASE IF EXISTS Apex";
$query1= "CREATE DATABASE Apex";
$query2= "CREATE TABLE Apex.Imagevalues(id int NOT NULL)";
$query3= "CREATE PROCEDURE Apex.MYLOOP()
BEGIN
DECLARE i int;
DECLARE str varchar(255);
SET i = 0;
WHILE i < 32 DO
SET str = CONCAT('Data_',i);
SET @sql = CONCAT('ALTER TABLE Apex1.Imagevalues ADD ',str,' DECIMAL(2,2);');
SET i = i + 1;
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END WHILE;
END";
$query4=" CALL MYLOOP() ";
$connection = mysqli_connect($server, $user, $pass);
if (!$connection) {
die('MySQL ERROR: ' . mysql_error());
}
if ( !mysqli_select_db($connection, $db) )
{
mysqli_query($connection,$query0);
mysqli_query($connection,$query1);
mysqli_query($connection,$query2);
mysqli_query($connection,$query3);
mysqli_query($connection,$query4);
}
return $connection;
}
?>