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)06/01 Report--
PHP connects to the database
1. Connect database function
The return value of mysqli_connect (hostname, username, password) is one of our connection objects. If the connection fails, an error report returns false.
two。 Judgment error function
Mysqli_connect_error (connection object) error message returns error message
Mysqli_connect_errno (connection object) error number 0 indicates a successful connection without errors
3. Select database function
Mysqli_select_db (connection object, database name to be selected); return true if the selection is successful, otherwise return false
4. Select character set
Mysqli_set_charset (connection object, character set to be selected); return true if the selection is successful, otherwise return false
5. Prepare sql statement
6. Send sql statement
Mysqli_query (connection object, sql statement to be sent); failure to get an object successfully returns false
7. Working with result set
7.1 get the number of entries
A) the number of records obtained by mysqli_num_rows (the object that sent sql successfully) can only be used by the select statement.
B) mysqli_affected_rows (connection object) the number of rows affected by the previous mysql operation is limited to the number of rows successfully inserted by the INSERT UPDATE DELETE operation with the return value of 1.
7.2 get the contents of the query result set
Mysqli_fetch_array (sending object) returns the results of the query as a mixed array, one at a time.
Mysqli_fetch_row (sending object) returns the results of the query as an indexed array, one at a time.
Mysqli_fetch_assoc (sending object) returns the results of the query as an associative array, one at a time.
7.3 when we add the operation, we can get the last inserted id.
Mysqli_insert_id (connection object) returns the last inserted id
8. Shut down the database
Mysqli_close (connection object)
/ / the eight steps of the Dragon in the Secret Book of php Kung Fu
/ / 1. Connect to the database
/ / 2. Error of judgment
/ / 3. Select a database
/ / 4. Select character set
/ / 5. Prepare sql statement
/ / 6. Send sql statement
/ / 7. Working with result set
/ / 8. Shut down the database
/ / 1. Connect to the database
/ / mysqli_connect ('hostname', 'username', 'password')
$link=@mysqli_connect ('localhost','root','123456')
/ / var_dump ($link)
/ / 2. Error of judgment
/ / mysqli_connect_error (connection object) error message
/ / mysqli_connect_errno (connection object) error number
/ / echo mysqli_connect_errno ($link)
/ / echo mysqli_connect_error ($link)
If (mysqli_connect_errno ($link)) {
Echo mysqli_connect_error ($link); exit
/ / echo 'error reconnecting'; exit
}
/ / 3. Select a database
Mysqli_select_db ($link,'ss21')
/ / 4. Select character set
Mysqli_set_charset ($link,'utf8')
/ / 5. Prepare sql statement
$sql= "SELECT id,name,sex,age,city FROM info"
/ / $sql= "INSERT INTO info (name) VALUES (NULL)"
/ / 6. Send sql statement
$result = mysqli_query ($link,$sql)
/ / 7. Working with result set
Echo mysqli_num_rows ($result)
/ / echo mysqli_affected_rows ($link)
/ / 8. Shut down the database
Mysqli_close ($link)
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.