Hongmu Notes
Home PHP PHP and mysql

PHP and mysql

PHP + MySQL database operations represent the most common combination for PHP database interactions; typically, working with MySQL databases using PHP involves tasks such as establishing database connections, reading data, executing queries, and performing backups. This is an essential foundational skill for developing large-scale PHP projects.

Practical Guide to Handling Prohibited Keywords in Website Advertising: Python-based Scanning + Baota Firewall Filtering + Keyword Database Management

Practical Guide to Handling Prohibited Keywords in Website Advertising: Python-based Scanning + Baota Firewall Filtering + Keyword Database Management Language Notes PHP PHP and mysql

Practical Guide to Handling Prohibited Keywords in Website Advertising: Python Scanning + Baota Firewall Filtering + Keyword Database Management. Author: Hongmu (QQ: 1810216796). First published on Hongmu Notes – GitHub: https://github.com/1810216796 (Full source code). 📌 Background: Recently, we received feedback from a client stating that their website contained prohibited advertising keywords – such as "First," "Best," and "National-Level" – which violated advertising regulations...
👁 106
A PHP function that adds or subtracts a specified amount of time from a timestamp and returns the result in a specified format.

A PHP function that adds or subtracts a specified amount of time from a timestamp and returns the result in a specified format. Language Notes PHP PHP and mysql

Here is a PHP function that adds or subtracts a specified amount of time from a timestamp and then outputs the resulting time in a specified format: <?php /** * Adds or subtracts a specified amount of time from a timestamp and outputs the resulting time in a specified format * * @param string $time-Date-time string in the format 'Y-m-d H:i:s' * @param int $seconds-The amount of time to add...
👁 148
Use PHP regular expressions to modify parameters in config.php.

Use PHP regular expressions to modify parameters in config.php. Language Notes PHP PHP and mysql

config.php <?php return array(// Database type: 'type' = 'mysql'; // Server address: 'hostname' = '127.0.0.1'; // Database name: 'database' = 'c51'; // Username: 'usernam...
👁 145
PHP PDO connects to the database, clears the database, and then imports the .sql file

PHP PDO connects to the database, clears the database, and then imports the .sql file Language Notes PHP PHP and mysql

To connect to the database using PHP PDO, then clear the database and import the .sql file, you can follow these steps: Connect to the database using PDO: $dbHost = "your hostname"; $dbName = "your database name"; $dbUser = "your username"; $dbPass = "your password"; $dbCharset = "u…
👁 201
After establishing a PHP connection to the root directory, create a database.

After establishing a PHP connection to the root directory, create a database. Language Notes PHP PHP and mysql

In PHP, connecting to the root user can be achieved by using the mysqli or PDO extensions. Using the mysqli extension: <?php $servername = "localhost"; $username = "root"; $password = "root"; // Establish a connection $conn = new mysqli($servername, $username, $password);
👁 139
Export database data to Excel using PHP

Export database data to Excel using PHP Language Notes PHP PHP and mysql

To export data from a database to an Excel file, you can use thePHPExcel library in PHP. Here is a simple example of code that usesPHPExcel to retrieve data from a database and export it to an Excel file: // Import thePHPExcel library: require_once('PHPExcel.php'); // Connect to the database: $servern...
👁 168
PHP – Query a single SQL record

PHP – Query a single SQL record Language Notes PHP PHP and mysql

You can use the mysqli or PDO extensions in PHP to query a single SQL record. Below are example codes for both methods: Using the mysqli extension to query a single SQL record: // Establish a connection $conn = mysqli_connect("localhost", "username", "password", "dbname"); // Check the connection...
👁 126
PHP connects to a database and executes SQL statements.

PHP connects to a database and executes SQL statements. Language Notes PHP PHP and mysql

In PHP, connecting to a database and executing SQL statements can be done through the following steps: Connect to the database using the `mysqli::connect()` function or the `PDO` class. For example: // Connect to the database using mysqli $servername = "localhost"; $username = "username"; $...
👁 191
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in Language Notes PHP PHP and mysql

This warning typically indicates that your SQL query has failed, causing the `mysqli::query()` function to return the boolean value `false` instead of a valid `mysqli_result` object. This can occur for various reasons, such as: a syntax or logic error in the SQL query; the absence or unavailability of the target table or database; or an error during database connection (e.g., invalid credentials or hostname). To resolve this issue...
👁 1884
PHP moves the contents of one table to another table, provided that the table fields are identical.

PHP moves the contents of one table to another table, provided that the table fields are identical. Language Notes PHP PHP and mysql

If you want to move the contents of one table to another table where the fields in both tables are identical, you can follow these steps: Connect to the MySQL database and select the database you wish to work with. $db = mysqli_connect("localhost", "username", "password", "my_database"); mysqli_s...
👁 360
1 2 3