1

I am trying to write a PHP program which should take input from user and match with data placed in MySQL.

I tried to write program using mysqli in php

new mysqli($hostname,$user,$password,$db)

This line does not establish a connection.

Then I changed some user privileges as described in https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04

But even then my PHP code is not connecting with MySQL. What should I do for establishing this connection.

Should I need to change some root permissions ?

2
  • 1
    send us your error and well written code, please see how to establish and debug a connection php.net/manual/en/mysqli.construct.php Commented Mar 20, 2019 at 18:41
  • This has nothing to do with permissions at the OS level. You haven't given us enough code that you've tried or shown us the error that you are getting. Make sure you have error reporting enabled and edit your question to include more of your code and the exact error you are getting. (ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);) Commented Mar 20, 2019 at 18:42

1 Answer 1

1

Try this :

/* CONNECTION */
$database_connection = new StdClass();

/** MySQL hostname */
$database_connection->server = 'localhost';

/** MySQL database username */
$database_connection->username = 'username';

/** MySQL database password */
$database_connection->password = 'password';

/** The name of the database */
$database_connection->name = 'dbname';

/* ESTABLISHING THE CONNECTION */
$database = new mysqli($database_connection->server, $database_connection->username, $database_connection->password, $database_connection->name);


if($database->connect_error) {

    echo 'db error';
}
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.