cancel
Showing results for 
Search instead for 
Did you mean: 
Go to solution
Highlighted

Database Connection Issue from php

I am migrating my site from classic linux to cpanel linux.  I keep running into unexpected issues.  cpanel uses higher versions of php (from 5.3 to 7.2) and mysql (from 5.5 to 5.6), which call for some code modifications (such as conversion of mysql_connect to mysqli_connect).

 

To get started, I made a backup of my database in classic, created a database with the same name user and password incpanel, then imported the contents of the backup.  Now I am failing to connect in the new version:

 

 

$db_host = "localhost";
$db_user = "my_db";
$db_pass = "my_pass";
$db_name = "my_db";

$link = mysqli_connect($db_host,$db_user,$db_pass,$db_name);

 

At this point mysqli_connect_errno() returns error 1044, which is

Error number: 1044; Symbol: ER_DBACCESS_DENIED_ERROR; SQLSTATE: 42000

Message: Access denied for user '%s'@'%s' to database '%s'

 

I am able to connect using these same credentials from the command line:

 

user@machine [~]$ mysql -h localhost -u my_db -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1310627
Server version: 5.6.43-cll-lve MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

(none)> 

So this tells me the host/database/password work.  But I can't establish a connection using the snippet of code above in php.

 

What am I missing?  It doesn't seem like this should be so hard!

 

Thank you.

 

2 REPLIES 2
Super User III
Super User III
Solution

Re: Database Connection Issue from php

@Tourist 

 

Did you grant permissions to the user to the database - in your screen capture you show that you connected to MySQL but didn't select the database.

 

My guess is if you grant permissions to the database to the user you should be good to go



I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community

Re: Database Connection Issue from php

That did it.  Thank you.