Skip to content
Advertisement

How can I access the localhost/phpmyadmin because all day I got This site can’t be reached?

I am using windows and trying to develop an app in php where I connect a database mySQL created on mySQL workbench. I connect with root and a saved pass. But it seems I cannot connect to the page afterwards.

I use Windows 10.

  <?php

define('db_user', 'what is the user?');
define('db_pass', 'mypass');
define('db_host', 'localhost');
define('db_name', 'movies');

&db_conn = mysqli_connect(db_host, db_user, db_pass, db_name);

if(!&db_conn){
    die('error connecting to database');
}
echo 'you have connected succesfully';
?>

My database is called movies. I don’t know what is the user?

Advertisement

Answer

phpMyAdmin is not a database; it is just one of the tools you use to manage what is inside. Your database is MySQL, which should be started and listening on a particular port. The default is usually 3306 or for MariaDB 3307. When MySQL server is located on the same machine as your web server, you can connect via localhost or 127.0.0.1.

If you haven’t set up any users in you MySQL server, then the default usually is root with no password. Check your users using this command:

SELECT * FROM mysql.user;

The user must also be authorized for an access via either localhost or IP, whichever you use.

Then to open a connection to MySQL in PHP using the mysqli class, you would usually use this code:

<?php

// your connection code
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli('localhost', 'root', '', 'movies');
$mysqli->set_charset('utf8mb4');
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement