How to fix HY000/2054 when implementing MySQL with Abyss Web Server? - php

I'm starting up a web server using Abyss X1, and just tried implementing a MySQL server through PHP with the following two scripts:
connect_db.php :
#Connect on 'localhost' for user 'admin'
#with password 'RoboticCowboy2019' to database 'site_db'.
$dbc = mysqli_connect
( 'localhost' , 'admin', 'password', 'site_db' )
OR die
( mysqli_connect_error() );
#Set encoding to match PHP script encoding.
mysqli_set_charset($dbc, 'utf8' );
and
require.php :
#Incorporate the MySQL connection script.
require ('../connect_db.php');
#Display MySQL version and host.
if(mysqli_ping($dbc)){
echo 'MySQL Server'.mysqli_get_server_info($dbc).'on'.mysqli_get_host_info($dbc);
}
However, when I go to http://localhost/require.php, I get these errors:
"Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /Applications/Abyss Web Server/connect_db.php on line 6"
"Warning: mysqli_connect(): (HY000/2054): The server requested authentication method unknown to the client in /Applications/Abyss Web Server/connect_db.php on line 6
The server requested authentication method unknown to the client"
I'm following the instructions of a book that I know is outdated, but I've been able to get around every problem until now. I've also read that it has something to do with MySQL updating and implementing sha2, while PHP still does not? I'm doing this for my compsci class, so I'd appreciate all the help I can get.
Thank you!

Alter the user
ALTER USER 'mysqluser'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlpassword';
or use
shell>mysql --default-auth=mysql_native_password

Related

Mysql wokbench db connection with php

Hai iam using phpmyadmin for a long time. now i want to change to mysql workbench. so i start with basics How can i connect my db.
i tried this..
$con = mysqli_connect("localhost:3306","root","","surendar");
Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
Warning: mysqli_connect(): (HY000/2054): The server requested authentication method unknown to the client
correct me if i am wrong.. Thanks

Unable to connect to SQL server using mysqli_connect, but MSSMS connects fine

I've read many questions similar to this but none of the answers have been relevant to me. I'm trying to access a SQL server using PHP. Both the SQL server and PHP are running on my Windows 10 machine. Here is my PHP code (the username and password are arbitrary):
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password');
This causes the following error:
PHP Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.
Here is my connection using MSSMS (which is successful):
EDIT:
I was able to solve my problem using this link: http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/
Using this link I enable SQL Browser, and set a static port to connect to SQL server with. However, I'm presented with a new error:
PHP Warning: mysqli_connect(): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
PHP Warning: mysqli_connect(): Error while reading greeting packet. PID=9920 in C:\HMUAPI\Index.php on line 7
PHP Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
My code has been changed to the following to cause this error: $connection = mysqli_connect('127.0.0.1:1434', 'hmuuser', 'password');
Add a database name
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password','dbname');
Also here is suggest - Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.
I guess the problem is, that you use MySQLi to connect to a MSSQL server.
You should use the correct MSSQL extension instead.
Microsoft published their SQL-Server for PHP driver on GitHub: https://github.com/Microsoft/msphpsql
Or you use the older extension which is documented in the PHP manual: http://de2.php.net/manual/en/book.mssql.php
And at least you can set up ODBC.
One of them should resolve your problem.

Warning: mysqli_connect(): (HY000/2002): An attempt was made to access a socket in a way forbidden by its access permissions

For two days yet I trying to resolve this problem
Warning: mysqli_connect(): (HY000/2002): An attempt was made to access a socket in a way forbidden by its access permissions.
My hosting is Azure and he has very bad interface. Programming language is PHP, I have database in same resource group with domain, account data is correct. what I do incorrect?
line with problem
mysqli_connect($SERVER, $USER, $PASSWORD, $DATABASE);
To get your connection string in a Web App with MySQL on CLearDB:
select your service in Azure Portal
click Settings
select Application Settings and scroll down to Connection String and click in "Show connection string values"
copy the middle column of the table you will get something like:
Database=YOUR_DATABASE_NAME;Data Source=YOUR_HOSTNAME;User Id=YOUR_USERNAME;Password=YOUR_PASSWORD
That's it, copy and replace in your code!
Protip: you can ping YOUR_HOSTNAME and use the IP instead the HOSTNAME to improve speed ;)

File Doesn't Work in Virtual Server

I have a PHP file called footer10.php that worked just fine in shared hosting. I moved it to a virtual server and it no longer works.
I get these errors when I pull the file up in a browser:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'apache'#'localhost' (using password: NO) in /var/www/.../...com/httpdocs/.../footer10.php on line 23
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/.../...com/httpdocs/.../footer10.php on line 23
Access denied for user 'apache'#'localhost' (using password: NO)
This is on line 23 of the file:
$presult = mysql_query("SELECT COUNT(*) FROM submission") or die(mysql_error());
Any idea what I need to do to make the file work on the virtual server?
Thanks in advance,
John
The error message means that PHP could not connect to the MySQL database.
If you're establishing the connection on your own using mysql_connect you should make sure that host, user and password are correct (according to the error message no password was specified)
The user name and the empty password makes me think you've relied on the mysql.default_* settings on your old server. You can specify a default server in your php.ini, refer to the manual for this. The connection will then be opened automatically by php.
So what you have to do is to find out correct credentials for your MySQL server. Then you either establish a connection using mysql_connect/mysql_pconnect or add it to the php.ini.
Access denied for user 'apache'#'localhost' (using password: NO) , what does this line mean ?
It means you need to update you're mysql connection settings with the correct ones ( username , password and host ) by this i mean you're mysql connection settings on the new server are different than the ones on the old server . Then make shure to move the database from one server to another .

"Unable to connect to PostgreSQL server" with pg_connect on localhost

I've a server with postgresql installed on the postgres user. When I do:
su - postgres
[entering the password]
psql
I can then execute queries on the database, that works fine.
However, from my php script (running on my own account):
$dbconnection = pg_connect("host=localhost port=5432 user=postgres password=XXXXXXX ");
(password crossed out of course)
I then get the message:
PHP Warning: pg_connect(): Unable to connect to PostgreSQL server:
FATAL: password authentication failed for user "postgres" FATAL:
password authentication failed for user "postgres" in
/home/username/script.php on line 18
I tried a lot of variations on the login string, but I keep getting the same message. Any ideas how I could try to solve this?
What is the current configuration for pg_hba.conf? And did you set a password for the database rol "postgres" ? su - postgres is for the Linux user "postgres", not for the database role "postgres". If you can start psql without entering the password, it looks like pg_hba.conf uses "trust" and not "password" of even better "md5". Or did you create a .pgpass file?
Your postgres may not listen on a network interface but on a filesystem socket in stead. What if you leave out host=/port= entirely?
Also, if you know the socketpath (and it's non-default), you may use that as host= argument
Be careful, the following (too short) connection string causes the mentioned error message ("Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "halmai" in..."):
pg_connect("dbname=halmai user=halmai password=halmai");
However, the more complete connection string works well:
pg_connect("host=localhost dbname=halmai user=halmai password=halmai");
My environment: php7.0.8.

Categories