0

Need some help please. My my site isn't connecting with the database.

Here my code:

<?php
$serverName="localhost";
$dbusername="root";
$dbpassword="";
$dbname="bank_db";
mysql_connect($serverName,$dbusername,$dbpassword)/* or die('the website 
is down for maintainance')*/;
mysql_select_db($dbname) or die(mysql_error());
?>

Would really appreciate the help.

Thanks!

3 Answers3

2

I have also came across the same situation and the following code block worked fine for me:

<?php
// URL Connection
$host='localhost';
$uname='root';
$pwd='';
$db='databasename';
//I created a connection object here to establish the connection with my database 
$con = mysql_connect($host,$uname,$pwd) or die("connection failed/");
mysql_select_db($db,$con) or die("db selection failed");
?>

Hope it works, Thanks.

0

The latest verson of php will through the depricated error for mysql_connect function. so you can use better mysqli function. This below link will give you more details about mysqli function.
https://www.w3schools.com/php/func_mysqli_select_db.asp

0

Use mysqli_ because mysql_ is deprecated.

You can ref this link for in detail for connection the database https://www.w3schools.com/php/php_mysql_connect.asp

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
Naren Verma
  • 2,135
  • 3
  • 26
  • 80