0
$dbser='localhost';
$user='root';
$pasw='';
$db='mlm';
$con=mysqli_connect($dbser,$user,$pasw)or die("mysql not connected:" .mysqli_connect_error());

My phpMyAdmin is working fine but the connection to the database is not working. I have also checked my password for root in phpMyAdmin is empty but still not working.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mcr
  • 13
  • 5
  • Where is running your DB ? On your host system ? I wonder if localhost is the host your PMA really connects to – Kern Nov 30 '20 at 08:48
  • Does this answer your question? [Access denied for user 'root@localhost' (using password:NO)](https://stackoverflow.com/questions/2995054/access-denied-for-user-rootlocalhost-using-passwordno) – GNassro Nov 30 '20 at 08:49
  • localhost xampp server – Mcr Nov 30 '20 at 08:57
  • 1
    You need to stop manually checking for errors. Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) and [Should I manually check for errors when calling “mysqli_stmt_prepare”?](https://stackoverflow.com/q/62216426/1839439) – Dharman Nov 30 '20 at 10:51

1 Answers1

-1

As you can see at the function doc:

mysqli_connect ([
    string $host = ini_get("mysqli.default_host")
    [, string $username = ini_get("mysqli.default_user") 
    [, string $passwd = ini_get("mysqli.default_pw")
    [, string $dbname = "" 
    [, int $port = ini_get("mysqli.default_port") 
    [, string $socket = ini_get("mysqli.default_socket") ]]]]]] 
    ) : mysqli|false

And the default for the $passwd argument is the result of ini_get() with a non-existent parameter:

Function ini_get():

Returns

Returns the value of the configuration option as a string on success, or an empty string for null values. Returns FALSE if the configuration option doesn't exist.

So try that:

$pasw = false;
// or 
$con = mysqli_connect($dbser, $user);