In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the six steps of PHP to connect to mysql database, the contents of the article are carefully selected and edited by the author, with a certain pertinence, and is of great significance to everyone's reference, the following is to understand the six steps of PHP to connect to mysql database together with the author.
/ / 1. Get connection
$conn=mysql_connect ('localhost','root','root')
If (! $conn) {
Die ("connection failed" .MySQL _ error ())
/ / 2. Select a database
Mysql_select_db ("test")
/ / 3. Set operation code (recommended)
Mysql_query ("set naems utf8"); / / make sure that the php program operates according to utf8
/ / 4. Send instruction sql (ddl (data definition statement)
/ / dml (data manipulation language update,insert,delete)
/ / dql (select), dtl (data transaction statement rollback commit...)
$sql= "select * from user1"
$res=mysql_query ($sql,$conn); / / if you don't add $conn, use the previous connection
/ / $res points to memory
/ / 5. Accept the returned results and process them.
While ($row=mysql_fetch_row ($res)) {
/ / $row is an array
Echo ""
Foreach ($row as $key = > $val) {
Echo "--$val"
}
Echo ""
}
/ / 6. Release resources and close the connection
Mysql_free_result ($res)
Mysql_close ($conn); / / recommended
After reading the above six steps for PHP to connect to mysql database, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.