How-to articles, tricks, and solutions about MYSQL

"Database query failed: Data truncated for column 'column_name' at row 1

This error message is indicating that a database query has failed due to data being too large to fit into a specific column in the database table.

Best practice multi language website

One best practice for implementing a multi-language website in PHP is to use a language detection library such as Text-Language-Detect.

Best way to check if mysql_query returned any results?

To check if a MySQL query returned any results, you can use the mysqli_num_rows function.

Calculate age based on date of birth

Here is some sample PHP code that calculates a person's age based on their date of birth:

Checking for an empty result (PHP, PDO, and MySQL)

In PHP, you can use the PDO (PHP Data Objects) extension to interact with a MySQL database.

Codeigniter's `where` and `or_where`

In CodeIgniter, the where method on the database class is used to add a WHERE clause to your query.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure is an exception that is thrown when there is a failure in the communication link between your Java program and the MySQL database. This can happen for a variety of reason

Commands out of sync; you can't run this command now

The "Commands out of sync; you can't run this command now" error in PHP usually occurs when you have called a MySQL function in an incorrect order.

Connect Java to a MySQL database

To connect a Java application to a MySQL database, you need to use the JDBC (Java Database Connectivity) API.

Docker MYSQL '[2002] Connection refused'

The '[2002] Connection refused' error in Docker when trying to connect to a MySQL container typically indicates that the MySQL server is not running or is not accessible on the network.

error in your SQL syntax; check the manual that corresponds to your MySQL server

This error message is indicating that there is a problem with the SQL syntax used in the query.

Error when preparing a multiple insert query

There are a few things that could cause an error when preparing a multiple insert query in PHP.

Example of how to use bind_result vs get_result

The mysqli_stmt::bind_result() method binds variables to a prepared statement for result storage.

Executing multiple SQL queries in one statement with PHP

In PHP, you can execute multiple SQL queries in one statement by using the mysqli_multi_query() function.

Export MySQL database using PHP

To export a MySQL database using PHP, you can use the mysqldump command-line utility or the mysqli extension.

Fatal error: [] operator not supported for strings

This error is usually caused when you are trying to use the square brackets [] to access a character in a string, but this is not supported in PHP.

How can I count the numbers of rows that a MySQL query returned?

You can use the mysqli_num_rows() function to count the number of rows that a MySQL query returned in PHP.

How can I employ "if exists" for creating or dropping an index in MySQL?

In MySQL, you can use the "IF EXISTS" clause when creating or dropping an index to prevent an error from occurring if the index does not exist.

How can I enable the MySQLi extension in PHP 7?

To enable the MySQLi extension in PHP 7, you need to follow these steps.

How can I prevent SQL injection in PHP?

There are several ways to prevent SQL injection attacks in PHP.

How do I connect to a MySQL Database in Python?

To connect to a MySQL database in Python, you can use the mysql-connector-python library.

How do I count unique visitors to my site?

There are several ways to count unique visitors to a website using PHP, but one common method is to use cookies.

How do I display a MySQL error in PHP for a long query that depends on the user input?

To display a MySQL error in PHP for a long query that depends on user input, you can use the mysqli_error() function.

How do I find out my MySQL URL, host, port and username?

To find out your MySQL connection details, you will need to look in your MySQL configuration files. The specific location of these files will depend on how you installed MySQL, but common locations include /etc/my.cnf,

1 2 3 4