How-to articles, tricks, and solutions about MYSQL

Lost connection to MySQL server at 'reading initial communication packet', system error: 0

This error message indicates that the client was unable to connect to the MySQL server.

MySQL - How to select rows where value is in array?

You can use the IN operator to select rows where the value is in an array.

MySQL Check if username and password matches in Database

To check if a given username and password match those stored in a MySQL database, you can use a SQL SELECT statement with a WHERE clause.

MySQL Database won't start in XAMPP Manager-osx

There could be a number of reasons why your MySQL database isn't starting in XAMPP on macOS.

MySQL Great Circle Distance (Haversine formula)

The Haversine formula is a mathematical formula that can be used to calculate the great-circle distance between two points on a sphere, such as the Earth.

MySQL JDBC Driver 5.1.33 - Time Zone Issue

If you are using MySQL JDBC Driver version 5.1.33 and you are experiencing issues with time zones, there are a few things you can try:

Mysql password expired. Can't connect

If your MySQL password has expired and you can't connect, you will need to reset the password.

MySQL query to get column names?

To get the column names of a table in MySQL, you can use the SHOW COLUMNS FROM command.

MySQL server has gone away - in exactly 60 seconds

The "MySQL server has gone away" error message typically indicates that the connection to the MySQL server was lost.

mysql_fetch_array() expects parameter 1 to be resource

It looks like you are trying to use a function from the MySQL extension in PHP, but you are getting an error saying that the first parameter should be a resource.

mysqli or PDO - what are the pros and cons?

mysqli and PDO are both PHP extensions used for interacting with databases.

mysqli::query(): Couldn't fetch mysqli

This error message is typically encountered when an attempt to execute a MySQLi query has failed.

Passing an array to a query using a WHERE clause

To pass an array to a WHERE clause in PHP, you can use the implode function to join the array elements with a comma separator and use them in your WHERE clause.

PDO get the last ID inserted

To get the last inserted ID using PDO, you can use the PDO::lastInsertId() method after inserting a row into the database.

PDO with INSERT INTO through prepared statements

To insert data into a database using PDO and prepared statements, you can use the following steps:

PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused

The error message "SQLSTATE[HY000] [2002] Connection refused" typically indicates that the client was unable to establish a connection to the database server.

PHP isset() with multiple parameters

The isset() function in PHP can take multiple parameters, and it will return TRUE if all of the variables passed to it have been set, and FALSE if any of them have not.

PHP mySQL - Insert new record into table with auto-increment on primary key

To insert a new record into a MySQL table that has an auto-increment primary key, you can use the INSERT statement with a list of comma-separated values.

PHP MYSQL UPDATE if Exist or INSERT if not?

You can use the ON DUPLICATE KEY UPDATE statement in your MySQL query when using PHP's mysqli or PDO libraries to accomplish this.

PHP/MySQL insert row then get 'id'

To insert a row into a MySQL database table and get the id of the inserted row in PHP, you can use the mysqli_insert_id() function.

php/mySQL on XAMPP: password for phpMyAdmin and mysql_connect different?

The password for accessing phpMyAdmin and the password for connecting to the MySQL server using the mysql_connect() function can be different.

PHPExcel and Text Wrapping

PHPExcel is a library for working with Microsoft Excel files in PHP.

phpMyAdmin allow remote users

phpMyAdmin is a web-based tool for managing MySQL and MariaDB databases.

Populate a Drop down box from a mySQL table in PHP

You can use the PHP MySQLi extension to connect to a MySQL database and retrieve the data from a table to populate a drop-down box.

Reloading .env variables without restarting server (Laravel 5, shared hosting)

In Laravel 5, you can use the php artisan config:cache command to compile all of your configuration into a single file, which will be loaded quickly by the framework.