In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The following mainly brings you what is the difference between using php database to connect mysql and mysqli. I hope these contents can bring you practical use. This is also the main purpose of this article that I edit the difference between mysql and mysqli using php database connection. All right, don't talk too much nonsense, let's just read the following.
1. Mysql is related to the concept of mysqli:
1. Both mysql and mysqli are function sets of php, and they are not closely related to mysql database.
2. Before the php5 version, the mysql function of php is generally used to drive the mysql database, such as the function of mysql_query (), which belongs to process-oriented 3. After the php5 version, the function function of mysqli has been added. In a sense, it is the enhanced version of the mysql system function, which is more stable, more efficient and more secure. Corresponding to mysql_query () is mysqli_query (), which belongs to object-oriented and drives mysql database by object-oriented operation.
Second, the difference between mysql and mysqli:
1. Mysql is a non-persistent connection function, and mysql will open a connected process for each link.
2. Mysqli is a permanent connection function. If mysqli runs mysqli multiple times, it will use the same connection process, thus reducing the overhead of the CVM. Mysqli encapsulates some advanced operations, such as transactions, as well as many methods available during DB operations.
Third, the usage of mysql and mysqli:
1:mysql (process mode):
$conn = mysql_connect ('localhost',' user', 'password'); / / Connect mysql database mysql_select_db (' data_base'); / / Select database $result = mysql_query ('select * from data_base'); / / second optional parameter, specify open connection $row = mysql_fetch_row ($result) / / fetch only one row of data echo $row [0]; / / output the value of the first field
PS:mysqli operates in a procedural manner. Some functions must specify resources, such as mysqli_query (resource identification, SQL statement), and the parameters of resource identification are put first, while the resource identification of mysql_query (SQL statement, "resource identification") is optional, and the default value is the last open connection or resource.
2. Mysqli (object mode):
$conn = new mysqli ('localhost',' user', 'password','data_base'); / / to use the new operator, the last parameter is to specify the database directly / / if not specified at construction time, the next sentence requires $conn-> select_db (' data_base') to implement $result = $conn-> query ('select * from data_base'); / / execute the sql statement $row = $result-> fetch_row () / / take a row of data echo = row [0]; / / output the value of the first field
Use new mysqli ('localhost', usenamer',' password', 'databasename'); an error will be reported as follows:
Fatal error: Class' mysqli' not found in...
Generally speaking, mysqli is not enabled, because the mysqli class is not enabled by default. In win, you need to change php.ini, remove the one before php_mysqli.dll, and compile mysqli in linux.
4. Mysql_connect () and mysqli_connect ()
1. Using mysqli, you can pass the database name as an argument to the mysqli_connect () function, or to the constructor of mysqli
two。 If you call the object query query () method of mysqli_query () or mysqli, the connection identity is required.
These are all the differences and usages of mysql and mysqli before connecting to the database. I hope it will help the students!
For the above about the use of php database connection mysql and mysqli methods are different, we do not find it very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.
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.