Reputation: 119
Am trying to connect to a xampp server but its not working this is my code:
session_start();
define('DB_NAME', 'login');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if ($link) {
die('Failed to connect: ' . mysql_error());
}
$db_select = mysql_select_db(DBNAME, $link);
if (!$db_select) {
die('Failed to connect:' . DBNAME . ':' . mysql_error());
}
Upvotes: 0
Views: 53
Reputation: 772
If you can solve the problem, try it with this sentence and you will see the error faster.
<?php $servername = "localhost"; $username = "username"; $password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
} ?>
Upvotes: 0
Reputation: 461
mysql is no longer usable. use mysqli and it will work fine
If you want to know more about it visit https://www.w3schools.com/php/func_mysqli_query.asp
Upvotes: 1