


Use mysqli extension technology to implement multiple data table queries
Use mysqli extension technology to implement multiple data table queries
In the actual project development process, a project often requires multiple data tables to store information , and these tables are related to each other through primary keys, then this article will introduce how to implement queries on multiple data tables.
Then in our previous article "How to use mysqli extension technology to view server connection error reports", we introduced the method of mysqli extension technology to view server connection error reports. Today we will introduce to you the use of mysqli extension technology to implement queries between multiple tables!
Technical points
Using mysqli technology to implement multi-table queries, the key is how to connect multiple tables through primary keys. The following is the code for implementing multi-table query in this example:
$sql = "select * from student,score where student.id=score.id"; $result = mysqli_query($link, $sql);
To implement query between multiple tables, all table names should be listed after the from keyword, and the table names should be separated by commas. At the same time, the connection conditions between multiple tables should be specified in the where keyword. For example, student.id=score.id in this example indicates that the connection between the student table and the score table is through the id field of the student table and the sid field of the score table. connect.
Implementation process
##(1) Create a php file to implement the connection with the MySQL database connections between. The code is as follows:
$link = mysqli_connect("localhost", "root", "root"); $conn = mysqli_select_db($link, "php_cn"); $sql = "select * from student,score where student.id=score.id"; $result = mysqli_query($link, $sql); $res = mysqli_fetch_array($result, MYSQLI_ASSOC);
(2) Implement queries between multiple tables. If there are records that meet the conditions in the student table and grade table, these records will be displayed. , otherwise it will prompt that there is no relevant information. The code is as follows:
序列 |
名字 |
语文成绩 |
数学成绩 |
外语成绩 |
##Note:
The "sequence" and "name" fields in the above result diagram come from the student data table, while the other fields come from the score data table.We have introduced the mysqli expansion technology to implement multi-table query here. Friends can try it locally. In the next article, we will continue to explain the mysqli expansion technology. Please read "
Realize memory recycling through mysqli extension technology》! 【Related tutorial recommendations】
1. Relevant topic recommendations: "
php operating mysql database"2.【
MYSQL Online Free Video Tutorial】3. Related video course recommendations: "
Elementary MySQLi Extension Library Video Tutorial 》
The above is the detailed content of Use mysqli extension technology to implement multiple data table queries. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When writing web applications using PHP, a MySQL database is often used to store data. PHP provides a way to interact with the MySQL database called MySQLi. However, sometimes when using MySQLi, you will encounter an error message, as shown below: PHPFatalerror:Calltoundefinedfunctionmysqli_connect() This error message means that PHP cannot find my

Solution to php unable to connect to mysqli: 1. Open the "php.ini" file; 2. Find "mysqli.reconnect"; 3. Change "mysqli.reconnect = OFF" to "mysqli.reconnect = on".

PDOPDO is an object-oriented database access abstraction layer that provides a unified interface for PHP, allowing you to use the same code to interact with different databases (such as Mysql, postgresql, oracle). PDO hides the complexity of underlying database connections and simplifies database operations. Advantages and Disadvantages Advantages: Unified interface, supports multiple databases, simplifies database operations, reduces development difficulty, provides prepared statements, improves security, supports transaction processing Disadvantages: performance may be slightly lower than native extensions, relies on external libraries, may increase overhead, demo code uses PDO Connect to mysql database: $db=newPDO("mysql:host=localhost;dbnam

If you encounter the following error message when using PHP to connect to a MySQL database: PHPWarning:mysqli_connect():(HY000/2002):Connectionrefused, then you can try to solve this problem by following the steps below. To confirm whether the MySQL service is running normally, you should first check whether the MySQL service is running normally. If the service is not running or fails to start, it may cause a connection refused error. you can

The running file of mysql is mysqld; mysqld is an executable file, which represents the Mysql server program. Executing this file can directly start a server process; and mysqld_safe is a startup script, which will indirectly call mysqld and also start a monitor. process.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

When using the mysqli extension to connect and operate a MySQL database, you sometimes encounter the error PHPFatalerror:Calltoundefinedmethodmysqli::prepare(). This error is usually caused by the following reasons: PHP has insufficient support for the mysqli extension; the mysqli extension is not loaded or configured correctly; there are syntax errors in the PHP code; the MySQL server is not correctly configured or running

When developing websites using PHP, database operations are very common. MySQLi is an extension commonly used in PHP to operate MySQL databases. It provides a relatively complete object-oriented interface, procedural interface, and supports operations of prepared statements. But sometimes when we use mysqli's prepared statements, we will encounter such an error: PHPFatalerror:Calltoundefinedfunctionmysqli_stmt_bin
