[Discussion] Advantages and disadvantages of using stored procedures in php + mysql

Source: Internet
Author: User
Tags database sharding
[Discussion] The advantages and disadvantages of using stored procedures in php + mysql have never been used in projects.
I have read some open-source systems and have never used stored procedures.
SQL statement execution
Is it necessary to use stored procedures in php projects?
Using Stored procedures should increase the speed and reduce the pressure on web servers
But it also increases the load on database servers.
For more experienced students
Let's discuss it together.


Reply to discussion (solution)

Basically, it is unnecessary to involve small database operations.
Frequent and complex use should significantly improve efficiency

No one is interested in this -. -

It is not very useful. Since this function is available, use it. The only explanation is to avoid repeated SQL statements.

It is not very useful. Since this function is available, use it. The only explanation is to avoid repeated SQL statements.
-. -Why is it useless?
It is very useful in some aspects. security
In addition, it is compiled and does not need to be parsed every time.
It will increase the database load.

It is not very useful. Since this function is available, use it. The only explanation is to avoid repeated SQL statements.
Thank you for your opinion.

Passing elder brother, senior expert, etc.
Let me talk about it. actually, I want to hear professional analysis.
Thank you.

Poor performance!

Poor performance!
Is it to improve performance -. -

I have read some open-source systems and have never used stored procedures. they all run SQL statements one by one.

Not all databases support stored procedures, such as mysql4.
In addition, the syntax for stored procedures varies with different databases.


Is it necessary to use stored procedures in php projects?

Stored procedures can greatly improve the efficiency of algorithms. if possible, use them.

Using Stored procedures should increase the speed and reduce the pressure on web servers

This is inevitable

But it also increases the load on database servers.

This understanding is wrong. do SQL statements executed in one line require no database server overhead?


The project has been using the stored procedure,

Relatively easy to maintain

I have never used stored procedures in mysql.

With memcache and static pages, the stored procedure becomes a weakness,

The storage process is not bad, it is difficult to modify, especially the dynamic script. it is easy to change and import the database,

Otherwise, now everyone writes the stored procedure and does not write SQL query statements.

I have read some open-source systems and have never used stored procedures. they all run SQL statements one by one.

Not all databases support stored procedures, such as mysql4.
In addition, the syntax for stored procedures varies with different databases.


Is it necessary to use stored procedures in php projects?

Stored procedures can greatly improve the efficiency of algorithms. if possible, use them.

Using Stored procedures should increase the speed and reduce the pressure on web servers

This is inevitable

But at the same time, the number is increased ......


They all have overhead, but they are different:


Functions are better than php built-in functions, which are different from external functions,
The usage is better than the difference between the compilation language and the interpretation language.


Especially in the Agile development era, in order to improve performance,
If you modify the compilation once and modify the compilation once, you don't know where to start with these overhead.




Thank you for your answers.

With memcache and static pages, the stored procedure becomes a weakness,

The storage process is not bad, it is difficult to modify, especially the dynamic script. it is easy to change and import the database,

Otherwise, now everyone writes the stored procedure and does not write SQL query statements.

Up ++

The stored procedure I wrote cannot be imported in phpmyadmin. you must execute mysql_query to import it.

Passing elder brother, senior expert, etc.
Let me talk about it. actually, I want to hear professional analysis.
Thanks for increasing the database server load.

Reference the reply from zy205817 on the 7 th floor:

Poor performance!

Is it to improve performance -. -Write the stored procedure for all your operations. Advantages and disadvantages!

When talking about the storage process, it reminds me of the fact that I was looking for an internship at my graduation. there was such a company, and the interview supervisor was still very beautiful. But her question is to write a login module for the stored procedure. So there is a conflict. ^_^.
However, high-load and high-concurrency websites should not be used. high-concurrency websites generally use master/slave, LVS, middleware, vertical Database Sharding, and horizontal table sharding.
Nosql is widely used. even if it is not a relational database, it is generally used for large websites. We recommend a redis instance.

Reference the reply of kxn308 on the eighth floor:

Reference the reply from zy205817 on the 7 th floor:

Poor performance!

Is it to improve performance -. -
Then, you can simply write the stored procedure for all your operations. Advantages and disadvantages!
Combined projects with advantages and disadvantages
Some are simple and unnecessary.
Performance will be improved

First, check whether the operations on your project database are complex, and whether developers are familiar with database programming.

The stored procedure itself improves performance, but it is small for simple projects.

In addition, you can use the advantages of stored procedures to encapsulate transactions. of course, it is based on complicated operations.

When talking about the storage process, it reminds me of the fact that I was looking for an internship at my graduation. there was such a company, and the interview supervisor was still very beautiful. But her question is to write a login module for the stored procedure. So there is a conflict. ^_^.
However, high-load and high-concurrency websites should not be used. high-concurrency websites generally use master/slave, LVS, middleware, vertical Database Sharding, and horizontal table sharding.
Nosql is widely used. even if it is not a relational database, it is generally used for large websites. We recommend a redis instance.
On the one hand, stored procedures improve SQL compilation efficiency, and on the other hand, they can also process complex business logic here.
What you are talking about is how to solve the performance problem under high load and high concurrency conditions, but cannot solve the problem of complicated business logic.
It took me a little time to learn about redis. it's hard to handle complicated business logic!

Can stored procedures improve cross-server performance?

For example, when php and mysql are deployed on different servers separately, if php is executed one by one, there will be many cross-server calls, with a large network latency. However, if a stored procedure is used, php can be called once.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.