In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
What is the difference between mysql and mysqli, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
The difference between mysql and mysqli:
Mysqli connections are permanent connections, while mysql connections are non-permanent connections.
Mysql connection: every time it is used for the second time, a new process will be reopened.
Mysqli connections: use only the same process all the time.
Benefit: this can greatly reduce the pressure on the server side.
Of course, if mysql also needs a permanent connection, you can use the function mysql_pconnect ()
Process-oriented use of mysqli:
01
$conn = mysqli_connect ('localhost',' root', '123,' db_test') or ('error')
02
03
$sql = "select * from db_table"
04
05
$query = mysqli_query ($conn,$sql)
06
07
While ($row = mysqli_fetch_array ($query)) {
08
09
Echo $row ['title']
ten
eleven
}
Object-oriented use of mysqli:
01
$conn = mysqli ('localhost',' root', '123,' db_test')
02
03
$sql = "select * from db_table"
04
05
$query = $conn- > query ($sql)
06
07
While ($row = $query- > fetch_array ()) {
08
09
Echo $row ['title']
ten
eleven
}
Mysql_connect and mysql_pconnect and mysqli_connect:
Connections opened by mysql_pconnect are not closed (even if mysql_close is called because it is not valid for it)
Similar to the connection buffer pool, if the next time there is the same user name from the same machine
For a connection to the same database, php automatically uses the connection that was established last time, without the need to establish a new one.
Benefit: it saves the overhead of establishing a connection with the database each time.
The downside: it needs to waste some memory and take up some connections.
So if an error occurs when the user visits a lot, change the max_connections parameter of mysql a little larger, or use mysql_connect () to solve the problem.
Simply put, MySQL_pconnect is used to establish a continuous connection between php and MySQL.
The general execution mode of php is to initialize all resources at the beginning of the script execution and release all resources after the script runs.
On the other hand, this is not the case with MySQL_pconnect. Every time, MySQL_connect is re-passed through tcp and so on.
To establish a relationship with a sql server, each connection consumes a lot of server resources.
When using pconnect, when there is a request to connect to MySQL, php checks whether the same connection (connecting to the same MySQL server with the same username and password) has been established.
Use this connection directly, if any, and it is worth noting that the same concept of connection is for the process.
Different process connections MySQL_pconnect establishment will establish multiple connections.
There is no functional difference between connect and pconnect, only a performance difference.
Generally speaking, php has two operation modes, one is to run as cgi, the other is to run as a module of apache.
As a cgi, connect is no different from pconnect, because every time cgi is run, it is destroyed and cleans up resources.
When php runs as an apache module, you can use persistent connections to the database, but there may be potential problems
Look at the php manual if you are installing cgi. Pconnection will never take effect.
The biggest disadvantage of a long connection is that in case a user is locked, the current process is permanently locked.
If your setting in apache is that the process is never destroyed, then...
In other words, try to use mysql_connect, because the run will be automatically interrupted after the end, in line with the style.
You can also use _ connect with mysql_pconnect, just like a link buffer pool
That means creating a class with mysql_connect and mysql_pconnect.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.