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: <?php // Assuming you have already established a MySQL connection // Retrieve the total of a field and select the three highest totals $servername = “localhost”; $username = “your_username”; $password […]

Read More

Export MySQL data into CSV using PHP

 To fetch data from a MySQL database and export it to CSV using PHP, you can follow these steps: <?php // Database connection details $servername = “localhost”; $username = “your_username”; $password = “your_password”; $dbname = “your_database_name”; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die(“Connection failed: ” […]

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