Mysql 8.0 Is Now Fully Supported in Php 7.4

by Janeth Kent Date: 27-10-2020 php mysql database


MySQL and PHP is a love story that started long time ago. However the love story with MySQL 8.0 was a bit slower to start… but don’t worry it rules now !

The support of MySQL 8.0’s new default authentication method in PHP took some time and was added in PHP 7.2.8 and removed in PHP 7.2.11. but now it’s fully supported in PHP 7.4 !

If you have installed PHP 7.4, you can see that the new plugin auth_plugin_caching_sha2_password is now available:

# php -i | grep "Loaded plugins|PHP Version " | tail -n2
PHP Warning:  Module 'mysql_xdevapi' already loaded in Unknown on line 0
PHP Version => 7.4.0
Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,
auth_plugin_mysql_clear_password,
auth_plugin_caching_sha2_password,
auth_plugin_sha256_password

So no need to create a user with mysql_native_password as authentication method in MySQL 8.0

In summary, if you want to use a more secure method to connect to your MySQL 8.0 form your PHP application, make sure you upgrade to PHP 7.4

The drawback of this new mysqli.so is that if you don’t modify the php.ini and by adding a value to mysqli.default_socket , when you try to connect to MySQL on localhost without specifying the socket path, the connection will fail with the following message:

PHP Warning:  mysqli::__construct(): (HY000/2002): 
No such file or directory in <name of your file>.php on line 45
An error occurred when trying to establish a connection to the database: Error #2002

You have then 2 solutions:

  1. add in php.ini a default value for mysqli.default_socket
  2. or specify the socket path when you initiate the connection to MySQL using mysqli in your code

This is also the default behavior on Ubuntu when using PHP 7.4 from ppa:ondrej/php repository.

Original article by Frédéric Descamps

 
by Janeth Kent Date: 27-10-2020 php mysql database hits : 1403  
 
Janeth Kent

Janeth Kent

Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN END DEVELOPMENT.

 
 
 

Related Posts

HTTP Cookies: how they work and how to use them

Today we are going to write about the way to store data in a browser, why websites use cookies and how they work in detail. Continue reading to find out how…

The most popular Array Sorting Algorithms In PHP

There are many ways to sort an array in PHP, the easiest being to use the sort() function built into PHP. This sort function is quick but has it's limitations,…

A roadmap to becoming a web developer in 2019

There are plenty of tutorials online, which won't cost you a cent. If you are sufficiently self-driven and interested, you have no difficulty training yourself. The point to learn coding…

10 PHP code snippets to work with dates

Here we have some set of Useful PHP Snippets, which are useful for PHP Developers. In this tutorial we'll show you the 10 PHP date snippets you can use on…

8 Free PHP Books to Read in Summer 2018

In this article, we've listed 8 free PHP books that can help you to learn new approaches to solving problems and keep your skill up to date.   Practical PHP Testing This book…

Best Websites to Learn Coding Online

You know and we know that it’s totally possible to learn to code for free... If you can teach yourself how to write code, you gain a competitive edge over your…

MYSQL: How to create a new user and give it full access only to 1 database

To create a new user in MySQL and give it full access only to 1 database, say dbTest, these are the MySQL commands to do that To create the user: CREATE USER…

PHP and XMP format: Create a Panorama 360/VR viewer in PHP and A-Frame

The Extensible Metadata Platform (XMP) is an ISO standard, originally created by Adobe Systems Inc., for the creation, processing and interchange of standardized and custom metadata for digital documents and…

How JSON data types work in mysql

First introduced in MySQL 5.7.8, the JSON data type is a specialized binary column type, similar to a blob , but with added machinery to optimize the storage and retrieval…

PHP: Basic Introduction to Namespaces

History of PHP Namespaces In PHP prior to 5.3 (2009), any class you define lived at the same global level as other classes. Class User, class Contact, class Db they're all together…

PHP 7.2 will be the first Programming Language to add Modern Cryptography to its Standard Library

Last week, the voting phase closed on an RFC to add libsodium to PHP 7.2. The result was unanimous (37 in favor, 0 against). When version 7.2 releases at the end…

Php: How to extend the highlight_string function

PHP has a cool function that automatically highlights PHP code called highlight_string(); Theoretically this could be used to roll your own code highlighting on a site, rather than rely on…