Himani
Himani

Reputation: 59

Php-mysql connectivity

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 ?

Upvotes: 1

Views: 39

Answers (1)

MimoudiX
MimoudiX

Reputation: 631

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';
}

Upvotes: 1

Related Questions