Home  >  Q&A  >  body text

Problems with PHP storage database efficiency

Program 1:

for($i=0;$<100;$){

Connect to the database;

Execute select in advance by a value;

Disconnect from the database;

Connect to the database;

Execute updata once to store data;

Disconnect from the database;

}

The program execution takes about 1.5-2 seconds

Program 2:

Connect to the database;

for($i=0;$i<100;$ i){

Execute select once;

Execute update once;

}

Disconnect the database connection;

Execution time-consuming 0.05-0.09 seconds

The key is that my storage database program is an interface document. The program will be executed only when someone else submits a post. Thousands of users will submit posts every second. How can I create a pdo? How about permanently connecting to improve storage efficiency? The program ends after returning the result to the post submitter, and the session or pdo connection is automatically closed.

八哥八哥414 days ago847

reply all(0)I'll reply

No reply
  • Cancelreply