Get the App
SLTechnology News&Howtos  ›  Development  › 

How to specify conditional query database by php

Shulou Source: shulou.com Published: 2022-06-03 10:51:19 11月15日 Update

This article mainly introduces php how to specify conditions to query the database, the article is very detailed, has a certain reference value, interested friends must read it!

Php specifies the conditions to query the database: 1, create a user table in the database; 2, use mysqli_select_db to select the database to operate; 3, specify query conditions through where; 4, use the mysqli_fetch_assoc function to convert the result set data into an array.

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

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

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

Within the test.php file, connect to the mysql database and use mysqli_select_db to select the database you want to operate on.

Within the test.php file, create a sql statement to get the data from the user data table, and specify the query criteria through where, for example, data with an id of 3, and then use the mysqli_query function to execute the sql statement.

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

Open the test.php file in a browser and view the results.

The above is all the contents of the article "how to specify the conditional query database by php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Data database file condition query function result build one content array method article statement selection value interest multiple buddy partner form Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB Apple Shulou Information macOS