How-to articles, tricks, and solutions about PHP

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

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

Convert date to day name e.g. Mon, Tue, Wed

In PHP, you can use the date function to convert a date to a day name.

Best practices to test protected methods with PHPUnit

There are a few ways you can test protected methods using PHPUnit:

Select records from today, this week, this month php mysql

To select records from today, you can use the following code:

Get an image extension from an uploaded file in Laravel

To get the extension of an uploaded file in Laravel, you can use the getClientOriginalExtension method of the UploadedFile instance, which is available in the request object.

Format code command for PHP/HTML in Visual Studio Code

To format code in Visual Studio Code, you can use the following steps:

PHP CURL DELETE request

To send a DELETE request with PHP using cURL, you can use the following code:

How to output (to a log) a multi-level array in a format that is human-readable?

There are a few different ways you can output a multi-level array in a human-readable format, depending on what you mean by "human-readable" and what you want to achieve.

Checking if date is weekend PHP

To check if a date is a weekend in PHP, you can use the date function to get the day of the week for a given date and then check if it is either 0 (Sunday) or 6 (Saturday).

Get current date, given a timezone in PHP?

To get the current date and time in a specific timezone in PHP, you can use the date_default_timezone_set function to set the timezone and then use the date function to get the current date and time.

How to separate DATE and TIME from DATETIME in MySQL?

You can use the DATE() and TIME() functions to extract the date and time parts of a DATETIME value in MySQL.

Check if xdebug is working

To check if Xdebug is working, you can try the following steps:

Calculate difference between two dates using Carbon and Blade

To calculate the difference between two dates using Carbon and Blade, you can use the following steps:

The Mix manifest does not exist when it does exist

This error message typically indicates that the Laravel Mix build process is unable to find the mix-manifest.json file that it generates when you run the npm run dev or npm run production command.

PHP: how can I get file creation date?

To get the file creation date in PHP, you can use the filectime() function.

Does file_get_contents() have a timeout setting?

Yes, the file_get_contents function in PHP does have a timeout setting.

Doctrine 2: Update query with query builder

To update an entry in a database using Doctrine's query builder, you can use the update method of the QueryBuilder class.

PHP cURL HTTP PUT

To make an HTTP PUT request using PHP's cURL functions, you can use the following snippet:

Laravel Eloquent inner join with multiple conditions

To perform an inner join with multiple conditions using Laravel's Eloquent ORM, you can use the join method on a query builder instance.

How can I write a file in UTF-8 format?

To write a file in UTF-8 encoding with PHP, you can use the fopen, fwrite, and fclose functions.

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.

Get all photos from Instagram which have a specific hashtag with PHP

To get all photos from Instagram that have a specific hashtag with PHP, you can use the Instagram API.

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.

Downloading a large file using curl

To download a large file using curl, use the following command:

PHP: Limit foreach() statement?

To limit the number of iterations in a foreach loop in PHP, you can use a simple counter variable and a break statement.