Home > Backend Development > PHP Problem > How to specify conditions to query the database in php

How to specify conditions to query the database in php

藏色散人
Release: 2023-03-12 20:04:02
Original
3851 people have browsed it

How to query the database by specifying conditions in php: 1. Create a user table in the database; 2. Use mysqli_select_db to select the database to be operated; 3. Specify query conditions through where; 4. Use the mysqli_fetch_assoc function to convert the results Just convert the set data into an array.

How to specify conditions to query the database in php

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to specify conditions to query the database in php?

In the mysql database, create a user table and insert multiple pieces of data into the table for testing.

How to specify conditions to query the database in php

Create a test.php file, and within the file, use the header() method to set the encoding format of the page to utf-8.

How to specify conditions to query the database in php

In the test.php file, connect to the mysql database and use mysqli_select_db to select the database to operate.

How to specify conditions to query the database in php

In the test.php file, create a sql statement to obtain the data of the user data table, and specify the query conditions through where, for example, the data with id 3 , and then use the mysqli_query function to execute the sql statement.

How to specify conditions to query the database in php

In the test.php file, use the mysqli_fetch_assoc function to convert the result set data into an array form, and use print_r to output the data.

How to specify conditions to query the database in php

Open the test.php file in the browser to view the results.

How to specify conditions to query the database in php

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to specify conditions to query the database in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template