-2

i have xampp installed on windows 10 but i updated to windows 11 and i changed port 3306 to 3307 now whene i try to connect to root it send back this error :

Access denied for user 'root@localhost' (using password:NO)

this is my code php

<?php
$host = 'localhost';
$user = 'root';
$pass = ''; // i don't use password
$db = 'projet';

$connect = mysqli_connect($host, $user, $pass, $db);
Progman
  • 16,827
  • 6
  • 33
  • 48
  • 1
    "it send back this error" care to show us the error? – easleyfixed Apr 07 '23 at 17:16
  • If the error is the Title I guess? If it is Denied, then you didn't pass it the proper credentials. The password is set to '', is there no password for root? Or did you type it like that to hide it for the example? – easleyfixed Apr 07 '23 at 18:03

1 Answers1

0

TL;DR Copy/paste

<?php
$connect = mysqli_connect(host: '127.0.0.1', username: 'root', port: 3307, dbname: 'project');

Explanation

There is a port property in the mysqli Object: https://www.w3schools.com/Php/func_mysqli_connect.asp

You should pass 3307 to it. Moreover, if your root user doesn't have a password (which is ok for testing but not for production) you shouldn't pass an ampty string. Instead, just leave it empty or null. To achieve this, I'd recommend using named parameters (https://stackoverflow.com/a/19127007/16682019)

Julius Babies
  • 955
  • 3
  • 6
  • 22