Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Six steps of connecting to mysql Database with PHP

2025-01-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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report