0

I'm attempting to use PHP to make a connection to a MySQL database as part of a website, and repeatedly getting two errors:

Warning: mysqli_connect(): (HY000/1698): Access denied for user 'root'@'localhost' in /var/www/html/file.php on line 12

Fatal error: Uncaught Error: Call to a member function query() on boolean in /var/www/html/file.php:20 Stack trace: #0 {main} thrown in /var/www/html/file.php on line 20

My code is just connecting and one query:

<?php
//Error reporting
ini_set('display_errors', 1);
error_reporting(~0);
//Server data
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "database";
$tblname = "table";
//Connection
$connect = mysqli_connect($servername, $username, $password, $dbname, null);
//Query
$sql = 'SELECT column1 FROM table';
//Send query
$result = $connect->query($sql);
$connect->close();
?>

Line 12 refers to $connect = mysqli_connect($servername, $username, $password, $dbname, null); and line 20 refers to $result = $connect->query($sql);

I've done a lot of searching for what might be the matter; if anyone has some insight, I'd greatly appreciate it. Thanks.

EDIT: I needed to setup a new user, problem is solved. Thanks all.

Atkeel
  • 3
  • 3

0 Answers0