简体   繁体   中英

Cannot connect to the MySQL database

This is my config.php file which I am using for the database connection. I am using WAMP server for the database and table creation. My database name is project and I have customer_info table on it. I don't know what to write in the password column as there is no mention of password in phpmyadmin.

<?php
define("MYSQLUSER","customer_info");
define("MYSQLPASS","Password1");
define("HOSTNAME","localhost");
define("MYSQLDB","project");
function db_connect(){
$conn = @new mysqli(HOSTNAME,MYSQLDB);
if($conn -> connect_error) {
die('Connect Error: ' . $conn -> connect_error);
}return $conn;
} 
?>
$conn = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

the object creation should be like this. You are using wrong parameters sequence.

You have configured your database on MySql server and you are accessing it via PHPMyAdmin (just to help you with terminology). Your config file should be edited this way:

<?php
define("MYSQLUSER","root");
define("MYSQLPASS","");
define("HOSTNAME","localhost");
define("MYSQLDB","project");
function db_connect(){
$conn = @new mysqli(HOSTNAME,MYSQLDB);
if($conn -> connect_error) {
die('Connect Error: ' . $conn -> connect_error);
}return $conn;
} 
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM