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

How to use php to read the queried data from mysql database

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How to use php to read the query data from the mysql database, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Php reads the queried data from the mysql database: 1, connect the mysql database through mysqli_connect; 2, set the character set coding format; 3, execute SQL statements; 4, deal with the result set.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php read the query data from the mysql database?

PHP+MySql realizes the reading of background data:

We are using PHP's php_mysqli extension

First of all, understand some basic usage

1. Use to connect to the database

Mysqli_connect ()

Parameter: ① host address ② MYSQL username ③ MYSQL password ④ Select the database ⑤ port number to which to connect

Return: return the identifier of the resource type if the connection is successful, and false if it fails

If we have more than one connection with Mysql, the various functions that operate the database later must pass in the connection symbol returned.

If we have only one connection to mysql, then the various functions that operate the database in the future will not have to pass in this identifier.

two。 Set character set encoding format

Mysqli_set_charset ()

3. Execute SQL statement

If it is an addition, deletion or modification, it will return whether the Boolean type is successful or not

If it is a query, the resource result set will be returned

$res=mysqli_query ()

4. Working with result set

Mysqli_fetch_assoc ($res); return associative array mysqli_fetch_row ($res); return index array mysqli_fetch_object ($res); return object mysqli_fetch_field ($res); return field information (field name, table name, database name, field type) mysqli_data_seek ($res, 0) for each column in the result set Set the result set pointer position to zero, reset the result set to the original mysqli_free_result ($res), release the query resource result set mysqli_close ($conn), and close the database connection

Let's implement a simple login function.

First, add the general configuration to a PHP file, and then use it to introduce it later.

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

Development

Wechat

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

12
Report