Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4235668
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:31:53+00:00 2026-05-21T02:31:53+00:00

The table[ file_request ] structure: user_id[INT] file_id[CHAR(10)] all_files This is the SQL code which

  • 0

The table[file_request ] structure:

user_id[INT]  file_id[CHAR(10)]  all_files

This is the SQL code which work fine in MySQL clien: I am using heidisql

DROP PROCEDURE IF EXISTS check_user_files;
DELIMITER \\  
 CREATE PROCEDURE check_user_files(IN p_user_id INT,IN p_file_id CHAR(10),IN p_all_files VARCHAR(500))
   BEGIN
        IF EXISTS(SELECT 1 FROM file_request WHERE user_id = p_user_id AND movie_id = p_file_id) THEN
            UPDATE file_request SET `requring_date`=NOW(),`all_files`= p_all_files WHERE `user_id`=p_user_id AND              `movie_id`=p_file_id;
        ELSE
            INSERT INTO file_request (`user_id`,`requring_date`,`movie_id`,`all_files`) 
            VALUES (p_user_id,NOW(),p_file_id,p_all_files);
        END IF; 
    END \\
DELIMITER ;
CALL check_user_files('23','T40431284','07 08 10 11 13 14');
DELIMITER ;
CALL check_user_files('23','F87951','01 02 03');

And I trying to create and execute the SQL query from PHP [didn’t work] :

// create the call procedure statements
foreach($fileData as $key=>$value){
    $callSP .= "DELIMITER ; \n
                CALL check_user_files('$userID','$key','$value');\n";            
}

$insert_file_request_query = "DROP PROCEDURE IF EXISTS check_user_files;
                              DELIMITER \\\\  
                              CREATE PROCEDURE check_user_files(IN p_user_id INT,IN p_file_id CHAR(10),IN p_all_files VARCHAR(500))
                                BEGIN
                                    IF EXISTS(SELECT 1 FROM file_request WHERE user_id = p_user_id AND movie_id = p_file_id) THEN
                                        UPDATE file_request SET `requring_date`=NOW(),`all_files`= p_all_files WHERE `user_id`=p_user_id AND `movie_id`=p_file_id;
                                    ELSE
                                        INSERT INTO file_request (`user_id`,`requring_date`,`movie_id`,`all_files`) 
                                        VALUES (p_user_id,NOW(),p_file_id,p_all_files);
                                    END IF; 
                                END \\\\
                              $callSP";

mysqli_query($conn,$insert_file_request_query);

The SQL query which created from PHP didn’t work as in the MySQL client!?

So, how can I fix it!?

[update1]

I found that the SQL query must in the special format [ the formate which work fine in the MySQL client] or shouldn’t work,I tried to copy and paste the query which echo from the PHP, the query code become one line and couldn’t execute in MySQL client,too.

[update2]
The code of create store procedure will work fine when I execute it alone from PHP.I mean,I split the whole process into three parts and execute them one by one.

part1: drop the procedure if it was exists; [using mysqli_query()]
part2: create the procedure;[using mysqli_query()]
part3:call the procedure;[using mysqli_multi_query()]

$insert_file_request_query = '';    

foreach($fileData as $key=>$value){
    $insert_file_request_query .= "CALL check_save_file_request('$userID','$key','$value');";            
}

mysqli_multi_query($conn,$insert_file_request_query);

And my final solution was to create the Store Procedure in MySQL and call it from the PHP.It works fine now.

Thank you very much!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:31:54+00:00Added an answer on May 21, 2026 at 2:31 am

    You can’t combine multiple statements in mysqli_query. Split out the definition of the stored procedure from the CALLs to it. If that still fails, we’ll need the full and exact error message that you receive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Mysql datatbase, and working on servlet: this is my Table schema: CREATE
I'm loading a table like this: mydata <- read.table(c:\\file.tab, header=TRUE, sep=\t, quote=\) I can
I try this command to upload a file (standard.xml) into table book the file
What is the php script for converting a mysql table to text file? I
I'm stuck, help me out !!! I have got a FILE table with: file_id
#define HASH_SIZE 5 // prototype int hash(char *word); // counter int counter; // node
I have an application that receives files with a flat table in DBF, which
I was able to read a RTF file (Data table) and get this to
i implemented a bloom filter(bit table) using three dimension char array it works well
I've configured a db w/ a FileStream group and have a table w/ File

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.