Ok, my problem was that i have to execute query to multiple mysql server, The easy way to do that to make connection to each of those servers and send query. And i work with php. In some part of my project i need to do hundreds of query at a time and normally php don't support multiple query to database. To do that i have to change some (.h) file in server what i don't have access. I't take lots more time to execute query cos every time send a query to the remote serve the php wait for the result and then send the next query. but if i can send all the query once then it will take less time. I saw searching net for that and couldn't find a better way. Then i thought to do it by my my salfe. And i thought to make a PROCEDURE where i will send all the query with some delimiter. And i coded the below PROCEDURE
CREATE PROCEDURE `execute_query`(var_complexe_query LONGTEXT,var_query_delimiter VARCHAR(20))
BEGIN
SET @new_string := var_complexe_query;
SET @execute_query:='';
SET @s_delimiter := var_query_delimiter;
SET @s_length := CHAR_LENGTH(var_query_delimiter)+1;
SET @end_loop := 0;
SET @loop_count := 0;
label1: LOOP
SET @loop_count = @loop_count + 1;
IF @loop_count > 1000 THEN LEAVE label1; END IF;
SET @execute_query:= SUBSTRING_INDEX(@new_string , @s_delimiter, 1);
SET @new_string := SUBSTRING(@new_string, CHAR_LENGTH(@execute_query)+@s_length);
PREPARE exequery FROM @execute_query;
EXECUTE exequery;
IF CHAR_LENGTH(@new_string) < 1 THEN LEAVE label1; END IF;
END LOOP label1;
any one who read this post and have any other idea please let me know.
CREATE PROCEDURE `execute_query`(var_complexe_query LONGTEXT,var_query_delimiter VARCHAR(20))
BEGIN
SET @new_string := var_complexe_query;
SET @execute_query:='';
SET @s_delimiter := var_query_delimiter;
SET @s_length := CHAR_LENGTH(var_query_delimiter)+1;
SET @end_loop := 0;
SET @loop_count := 0;
label1: LOOP
SET @loop_count = @loop_count + 1;
IF @loop_count > 1000 THEN LEAVE label1; END IF;
SET @execute_query:= SUBSTRING_INDEX(@new_string , @s_delimiter, 1);
SET @new_string := SUBSTRING(@new_string, CHAR_LENGTH(@execute_query)+@s_length);
PREPARE exequery FROM @execute_query;
EXECUTE exequery;
IF CHAR_LENGTH(@new_string) < 1 THEN LEAVE label1; END IF;
END LOOP label1;
END$$
If i have like 3 queries query1,query2 adn query3 so i add all the quires with delimiter like "$$_$$" what im sure not in my query like in php
$query = $query1. "$$_$$".$query2. "$$_$$".$query3;
and call the PROCEDURE
`execute_query($query,"$$_$$");
and the PROCEDURE separate all the quires from the string by delimiter and execute themany one who read this post and have any other idea please let me know.
Comments
Post a Comment