Having trouble with PHP/MySQL

The table actually already exists. I ran the SQL script on my own.
I have PHP Version 7.1.7

Also, the file_get_contents() isn’t what’s causing it, it’s the PDO object itself.

The connection error is because you are using an incompatible authentication algorithm between the php driver and the database server. Since you are using a later php version, that would lean toward an out of date database version. What is the database server type and version and how did you obtain/install both the web server/php and the database server? Is this a recent install of the web server/php and the database server or has there been a number of upgrades to either or both?

1 Like

I’ve had PHP installed for at least a year. However, the SQL database has been up for a week, if that.

Run the alter SQL you posted. There is a “bug” with Php and Mysql 8 that will be fixed in php 7.4

1 Like

Is PHP 7.4 out yet? And where do I run the alter at, in the SQL command prompt, in the data.sql file, or somewhere else?

Run it from the command line, phpmyadmin or any other mysql gui.

1 Like

I ran this and it still has the error.

The posted code isn’t using the root user, so the ALTER statement isn’t affecting the correct user. You would need to ALTER the the setting for the mongoose username.

However, see the following from the php.net PDO_MySQL documentation -

This is because MySQL 8 defaults to caching_sha2_password, a plugin that is not recognized by the older PHP (mysqlnd) releases. Instead, change it by setting default_authentication_plugin=mysql_native_password in my.cnf.

So, find the my.cnf for your database server and add/edit a line setting the default_authentication… Stop and start your database server to get any change made the my.cnf to take effect.

1 Like

What’s a cnf and where would I find it?

I did a search on it in the C drive and, after searching forever, it came up with nothing when I looked up my.cnf.

I did find this, though. https://stackoverflow.com/questions/2482234/how-do-i-find-the-mysql-my-cnf-location#2485758

Supposedly the file is where the SQL server is. However, I’m not sure where that would be.

Ok, I think I found the file my.ini but not my.cnf.

I added this to the end of my.ini:

default_authentication_plugin=mysql_native_password

The error is still persisting with SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

Also, to make matters worse, for some reason I can no longer run the MySQL command line client. (Even after I removed the my.ini edit to see if that was it.)

Also, how do I start and stop the database server? it’s a nightmare to look this stuff up online as I’m getting all sorts of different sql guis and programs and operating systems.

Now I’m getting a new error.

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

This happened after I put that thing you said into the end of my.ini and then restarted the computer. (Also, after editing my.ini, I’m having trouble getting the MySQL command line thing to open, though that might just be a coincidence.)

I tried a bunch of that and now have a new error:

I changed the user to mongoose and the password to Melissa89 on the config.php and I thought that might possibly be why it wasn’t connecting but the error is still there. Did I break something by putting the default_authentication_plugin=mysql_native_password

at the end of my.ini?

I keep getting SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. now instead of SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

The current error is typical for a db server that isn’t running.

1 Like

Why isn’t it running? Was I not supposed to put that code at the end of the my.ini file? It seems that I run into one error after another. :sob:

At this point, I recommend that you save any .php files you have created, uninstall the web server/php and database server (you never answered what versions or how you obtained them), and install one of the ALL IN ONE xAMP packages which are pre-configured to work together.

1 Like

I got mysqli from Windows. I have had PHP for a while. Do I have to uninstall that one too?

UPDATE: I tried to install this WAMP thing and now it’s saying MSVCR110.dll is not there and is suggesting I reinstall it. What’s wrong now?

Did I go to the wrong site or get the wrong version? I told it to get 64 bit for Windows.

Some online people had this problem and suggested reinstalling Microsoft Visual C++ 2015 but I tried that and it STILL won’t work. I tried downloading the DLL file and it STILL won’t work.

Something told me to install both 32 and 64 bit versions for 64 bit for Microsoft Visual C++ but the OS won’t let me.

UPDATE: Now the Wamp thing is running but all it does it pop up for a bit and then go away. (I was able to get it to find the DLL file by installing the Microsoft Visual Stuido 2012.)

However, I’m still seeing IIS when I start localhost, not WAMP.

Also, on the site, now I have a new error:

SQLSTATE[HY000] [1045] Access denied for user ‘root’@‘localhost’ (using password: YES)

What WAMP “thing”? Get rid of whatever “thing” you have and install Laragon and be done with it.

1 Like

I got rid of the program and installed this largon thing and now I’m getting this error again:

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

Did you get rid of every other trace of php and mysql? Did you start Laragon from it’s control menu?

No, I just left the IIS and the WHAMP and mysqli there. I have Laragorn as a file on my desktop.

I’m afraid to get rid of IIS as it might kill my PHP files in wwwroot.

Also, I don’t want to accidentally break PHP, which IS working at the moment. Can’t I keep them both?

Laragon is not a file, it is an installer

Edit: Back up your files and do what I said. Laragon is EVERTHING you need all in one.

Sponsor our Newsletter | Privacy Policy | Terms of Service