Tag: MySQL

Linux MySQL commands

SET FOREIGN_KEY_CHECKS = 0;<br>DROP TABLE IF EXISTS <code>table1, table2, table3, …;SET FOREIGN_KEY_CHECKS = 1;</code> Take Backup of Database

Read More

Get total of MySQL column and show highest totals

To get the total of a MySQL field and then select the three highest totals from the table, you can use the following PHP script: Make sure to replace ‘your_username’, ‘your_password’, ‘your_database_name’, ‘field_name’, and ‘table_name’ with the actual values for your MySQL configuration and table structure. In this script, the SQL query uses the SUM […]

Read More

Import CSV data into MySQL using PHP

Here’s a detailed example of how to import data from a CSV file into a MySQL database using PHP. The script processes each row one by one, displays a success message for each successfully inserted row, and stops the process if any error occurs, showing the error message. Prerequisites: Ensure you have a MySQL database […]

Read More

Covert all date data format from VARCHAR to DATE in any MySQL table

Converting varchar data to date format in MySQL involves several steps. Here’s a method to achieve this: Assuming your varchar date column is named date_column and your table is named your_table, you can follow these steps: Remember to take a backup of your data before making such changes to your database. Incorrectly manipulating your database […]

Read More

Export MySQL data into Excel using PHP

To fetch data from a MySQL database and export it to Excel, you can use PHP along with a library like PHPExcel or PHPSpreadsheet (which is the successor of PHPExcel). Here, I’ll provide an example using PHPExcel. Please note that PHPExcel is now deprecated, and PHPSpreadsheet is recommended for new projects. If you’re starting a […]

Read More