0

I have a website that I should put on my domain.I have encountered an issue when I tried connecting to MySQL database so my code is not working. When I put

define("DB_HOST","http://domain");
define("DB_USER","user");
define("DB_PASS","password");
define("DB_NAME","dbName");

$connection = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
if(!$connection){
    die();
}
mysqli_set_charset($connection,"utf8");

I get this error in log

Failed to connect to MySQL: Plugin http could not be loaded: /usr/lib64/mysql/plugin/http.so: cannot open shared object file: No such file or directory

otherwise, I tried to remove that HTTP and just use the domain as DB_HOST, but then I get error

 define("DB_HOST","mydomain.com");
    define("DB_USER","user");
    define("DB_PASS","password");
    define("DB_NAME","dbName");
    
    $connection = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
    if(!$connection){
        die();
    }
    mysqli_set_charset($connection,"utf8");

PHP Warning: mysqli_connect(): (HY000/2002): Can't connect to MySQL server on 'domain.com' (115) in /home3/domain/public_html/a/i.php on line 7

Can anyone please help me find the solution to make this work?

1
  • 1
    http://domain is wrong, and domain.com is wrong if the mysql server is not open to the internet and the user is allowed to connect from any host. If you're on shared hosting enter the details provided by your host. If your working on one server like a VPS and mysql is installed locally use localhost or 127.0.0.1 for the domain. You need to provide more details about the setup. Commented Aug 31, 2020 at 13:03

1 Answer 1

2

Here's how I define a MYSQLI connection;

 $con = mysqli_connect("localhost","username","password","database");

When you want to run an operation you just invoke the $con variable. If you have issues check the permissions for the MYSQL user, they should at the very least include;

delete
insert
select
show view
update

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.