tags:

views:

48

answers:

5

I use remote server to store values into MySQL database.

I don't use any SELECT queries, only INSERT, DELETE and UPDATE.

When I execute 70,000 queries I have trouble with speed.

I was trying mysql_unbuffered_query and I saw little performance profit but it's still too slow.

I remember that some functions in PHP allow me to execute several lines, separated by ;

$something=<<<something

query1 ;
query2 ;
query3 ;

something;

execute($something)

Can someone can help me remember ?

Maybe in PDO ?

+2  A: 

The feature you are thinking of is the PHP heredoc syntax. It allows you to do multiple line strings using <<<.

But PDO does not support multiple SQL statements at once. You need to split them up and execute each one individually. You said this was too slow for you, so you may not be able to use PDO.

If you have many statements that are the same but with different parameters, you can use PDO prepared statements. With these, you can prepare the statement once, then just execute it with different parameters. If you have multiples types of statements, you will need to prepare each individually. You can read more about prepared statements here. They also have the benefit of not being vulnerable to SQL injection.

Alan Geleynse
You don't understand me correct. I don't have problem with executing this queries. But when i send query, i have to wait until it finish. It work great when i use local server, but when i use remote... it take lot of time. 70 000 queries, done in about one hour... Thats why i want send about 100 queries in one request.. this will make operation faster.
marc
+1  A: 

You need mysqli.multi-query. Just create the SQL-command (for example, like you were doing with that heredoc syntax) and execute it. Make sure the separator is configured correctly.

Konerak
Does mysqli is pre-instaled on most shared hostings ?I'm writing application what require back compatibility with php4 and php5 :/
marc
A: 

If you don't want to wait, INSERT DELAYED and cousins, with still seperate queries, are the way to go. If you cannot use them (for instance, you are using the InnoDB storage engine), you'll have to feed them to another process which can / is allowed to wait them out.

For the latter option I especially like the job/worker/client concept of gearman, although it takes a little bit of work to get a pool of non-webserver related workers running it's a godsend when you just want to inform a user you will do the requested alterations, possibly with a callback when it's finished, but essentially letting the user go on his/her merry way.

Wrikken
A: 

If you posted the code from some of your slower queries, maybe we can help tune them. Often times you miss something just because you've been looking at the code for so long.

PMV
A: 

Why don't you just call all the statements at once, separated by semi-colons?

mysql_query("
    INSERT INTO something (some, thing) VALUES (123, 456);
    UPDATE AT something STATEMENTS;
    THIRD QUERY; 
    FOURTH MYSQL QUERY; 
    AND SO ON;
");
Codemonkey