PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client

I’m running MySQL version 8 on PHP 7.0. I’m getting the following error when I try to connect to my database from PHP: Connect Error: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client PHP might show this error Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in D:\xampp\htdocs\reg\server.php … Read more

Imploding an associative array in PHP

The problem with array_map is that the callback function does not accept the key as an argument. You could write your own function to fill the gap here: Now you can do that:

PDO closing connection

Just a rather simple question with regards to PDO compared to MySQLi. With MySQLi, to close the connection you could do: However with PDO it states you open the connection using: but to close the connection you set it to null. Is this correct and will this actually free the PDO connection? (I know it … Read more

PHP if not statements

Your logic is slightly off. The second || should be &&: You can see why your original line fails by trying out a sample value. Let’s say $action is “delete”. Here’s how the condition reduces down step by step: Oops! The condition just succeeded and printed “error”, but it was supposed to fail. In fact, … Read more

SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

The file that you downloaded (http://curl.haxx.se/ca/cacert.pem) is a bundle of the root certificates from the major trusted certificate authorities. You said that the remote host has a self-signed SSL certificate, so it didn’t use a trusted certificate. The openssl.cafile setting needs to point to the CA certificate that was used to sign the SSL certificate … Read more

How to make a countdown using PHP

If your need your counter to be displayed only on page refresh and be static once the page is loaded, then PHP will be fine. If you need the countdown to get refreshed when the page is displayed, you’ll need to use JavaScript. Personally I would go for something already implemented, like that small script.

How do I expire a PHP session after 30 minutes?

You should implement a session timeout of your own. Both options mentioned by others (session.gc_maxlifetime and session.cookie_lifetime) are not reliable. I’ll explain the reasons for that. First: session.gc_maxlifetimesession.gc_maxlifetime specifies the number of seconds after which data will be seen as ‘garbage’ and cleaned up. Garbage collection occurs during session start. But the garbage collector is … Read more

Message: Trying to access array offset on value of type null [duplicate]

This happens because $cOTLdata is not null but the index ‘char_data’ does not exist. Previous versions of PHP may have been less strict on such mistakes and silently swallowed the error / notice while 7.4 does not do this anymore. To check whether the index exists or not you can use isset(): Which means the line should look something like … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)