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!
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.
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
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);
}
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.