Foreword: PHP is a programming language that is relatively easy to get started with, and PHP has a lot of built-in functions. Therefore, it is particularly important to understand and master these built-in functions. Next we will analyze some of the built-in functions of PHP.
I will continue to organize it for you in the future.
Recommended php video tutorial: https://www.php.cn/course/list/29/type/2.html
Understanding of phpMysqli functions:
1. What is php mysqli?
php mysqli = php nysqli improved
The mysqli function allows you to access the database server.
Notice! The mysqli extension is available for mysqli version 4.1.13 or newer.
2. How to use mysqli function?
If you want to use the mysqli function, you must add support for the mysqli extension when compiling php.
For more information about installation, please visit: http://www.php.net/manual/en/mysqli.installation.php
For details about running configuration Detailed information address: http://www.php.net/manual/en/mysqli.configuration.php
3. Function introduction:
1, mysqli_query(connection, query, resultmode)
Function
resultmode parameter is optional, any one of the following
MYSQLI_STORE_RESULT
(Default)
MYSLQLI_USE_RESULT
(Available for retrieving large amounts of data)
Description: Execute sql statement
Instance:
<?php //配置数据库基本信息 $localhost = 'localhost'; $user = 'zmz'; $password = '20040315'; $dbname = 'zmz'; $port = 3306; //连接数据库 $conn = mysqli_connect($localhost,$user,$password,$dbname,$port); //检查连接 if(!$conn) { die('连接失败!'.mysqli_connect_error()); } //连接成功,定义sql语句 $sql = "SELECT * FROM pro1 where 关键 词 like '%么%'"; //执行sql语句 $result = mysqli_query($conn, $sql); var_dump($result); mysqli_close($conn); ?>
2, mysqli_affected_rows()
Function
Description: Output the affected rows from different queries Record number of rows:
Instance:
<?php //配置数据库基本信息 $localhost = 'localhost'; $user = 'zmz'; $password = '20040315'; $dbname = 'zmz'; $port = 3306; //连接数据库 $conn = mysqli_connect($localhost,$user,$password,$dbname,$port); //检查连接 if(!$conn) { die('连接失败!'.mysqli_connect_error()); } //连接成功,定义sql语句 $sql = "SELECT * FROM pro1 where 关键词 like '%么%'"; //执行sql语句 $result = mysqli_query($conn, $sql); //print_r($result); //die(); //判断受影响的行数 echo mysqli_affected_rows($conn); ?>
3、mysqli_autocommit()
Function
Description: Turn off or enable automatic data submission
Instance:
<?php //配置数据库信息 $localhost = 'localhost'; $username = 'zmz'; $password = '20040315'; $dbname = 'zmz'; $port = 3306; //连接数据库 $conn = mysqli_connect($localhost,$username,$password,$dbname,$port); //检查连接 if(mysqli_connect_errno($conn)) { die('连接失败!'.mysqli_connect_error()); } //echo '成功'; //die(); //连接成功,关闭自动提交 mysqli_autocommit($conn, false); //执行插入操作 $sql = "INSERT INTO demo (id,name,age) VALUES(2,'zmz',16)"; mysqli_query($conn,$sql); //手动提交事务 $result = mysqli_commit($conn); var_dump($result); //关闭连接 mysqli_close($conn); ?>
4, mysqli_commit()
Function
Description: After turning off automatic submission, manually submit the current transaction transaction of the specified database connection
Instance:
<?php //配置数据库信息 $localhost = 'localhost'; $username = 'zmz'; $password = '20040315'; $dbname = 'zmz'; $port = 3306; //连接数据库 $conn = mysqli_connect($localhost,$username,$password,$dbname,$port); //检查连接 if(mysqli_connect_errno($conn)) { die('连接失败!'.mysqli_connect_error()); } //echo '成功'; //die(); //连接成功,关闭自动提交 mysqli_autocommit($conn, false); //执行插入操作 $sql = "INSERT INTO demo (id,name,age) VALUES(2,'zmz',16)"; mysqli_query($conn,$sql); //手动提交事务 $result = mysqli_commit($conn); var_dump($result); //关闭连接 mysqli_close($conn); ?>
5, mysqli_rollback()
Function
Description: Turn off automatic submission, manually commit the transaction, and roll back the current transaction.
Returns true if successful, otherwise returns false.
Example:
<?php //配置数据库信息 $localhost = 'localhost'; $username = 'zmz'; $password = '20040315'; $dbname = 'zmz'; $port = 3306; //连接数据库 $conn = mysqli_connect($localhost,$username,$password,$dbname,$port); //检查连接 if(mysqli_connect_errno($conn)) { die('连接失败!'.mysqli_connect_error()); } //echo '成功'; //die(); //连接成功,关闭自动提交 mysqli_autocommit($conn, false); //执行插入操作 $sql = "INSERT INTO demo (id,name,age) VALUES(3,'zyl',22)"; mysqli_query($conn,$sql); //手动提交事务 $result = mysqli_commit($conn); mysqli_rollback($conn); //var_dump($result); //关闭连接 mysqli_close($conn); ?>
The above is a supplement to the mysqli function, I hope it will be helpful to everyone. Thanks!
Recommended related articles: https://www.php.cn/php-weizijiaocheng-428624.html
The above is the detailed content of Summary and detailed introduction of php mysqli function (2). For more information, please follow other related articles on the PHP Chinese website!

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

Tracking user session activities in PHP is implemented through session management. 1) Use session_start() to start the session. 2) Store and access data through the $_SESSION array. 3) Call session_destroy() to end the session. Session tracking is used for user behavior analysis, security monitoring, and performance optimization.

Using databases to store PHP session data can improve performance and scalability. 1) Configure MySQL to store session data: Set up the session processor in php.ini or PHP code. 2) Implement custom session processor: define open, close, read, write and other functions to interact with the database. 3) Optimization and best practices: Use indexing, caching, data compression and distributed storage to improve performance.

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
