php file not creating Procedure for Database

  database, mysqli, php, windows, xampp

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

It got stuck at $query3

<?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= "DELIMITER //
        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 Apex.Imagevalues ADD ',str,' float;');
                       SET i = i + 1;
                       PREPARE stmt FROM @sql;
                       EXECUTE stmt;
                       DEALLOCATE PREPARE stmt;
              END WHILE;
         END";

    $query4="CALL apex.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;
    }
    ?>

Source: Windows Questions

LEAVE A COMMENT