skip to Main Content

$mysqli = new mysqli('localhost', 'root', '789456','ai');

I write this and turn on the xampp
mysql have aipharm name , it’s host is local(127.0.0.1),username is just root, password is same too and port is 3310.
At the left side, mysql icon with the name ai is shown but i can’t connect with that mysql database… am i use workbench? or did i wrote wrong code?

If possible i want just use only vscode

2

Answers


  1. You are passing wrong parameter, as you said password is also root but you configured something else.

    $mysqli = new mysqli("127.0.0.1", "user", "password", "database");
    
    echo $mysqli->host_info . "n";
    

    This will print

    Localhost via UNIX socket
    127.0.0.1 via TCP/IP
    
    Login or Signup to reply.
    1. make sure your mysql username & password is right. Usually root account has no password so if you didn’t add a password to the root account leave the password section empty.

    2. if you can’t find your username or password[1]
      [1]: https://www.youtube.com/watch?v=1Sl5aQg8E4I

    3. Or you can create a new user[2]
      [2]: https://www.youtube.com/watch?v=zS4g31spQ00

    use this I think you easily understand & use it 🙂

    <?php 
    $databaseHost = 'localhost';
    $username='root';
    $password='';
    $databaseName = 'EnterYourDatabaseNameHere';
    $conn = mysqli_connect($databaseHost, $username, $password, $databaseName);
    $error=array(); ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search