0

This connection seems to be failing. not sure why. Just trying to make this connection work so the rest of the project works.

<?php

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

// Create connection
$connection = mysql_connect('$servername', '$username', '$password');

// Check connection
if (!$connection){
    die("Database Connection Failed" . mysql_error());
} 

$select_db = mysql_select_db('$dbname');
if (!$select_db){
    die("Database Selection Failed" . mysql_error());
}

?>
  • 3
    because, variables don't get parsed in single quotes. – Funk Forty Niner Aug 04 '16 at 16:24
  • RTM http://php.net/manual/en/language.variables.php – Funk Forty Niner Aug 04 '16 at 16:26
  • putting double quotes didn't change anything. –  Aug 04 '16 at 16:26
  • Have you tried manually connecting with these credentials at MYSQL console? – Rahi Aug 04 '16 at 16:27
  • well then, my guess is that you can't use the mysql_ API anymore or that your connection failed outright. – Funk Forty Niner Aug 04 '16 at 16:27
  • Why would I not be able to use mysql_ API? –  Aug 04 '16 at 16:28
  • Beats me. I don't know which version of PHP you're using, or how you're accessing this. as localhost or file:/// ? – Funk Forty Niner Aug 04 '16 at 16:28
  • it's just a local MySql server and some php. should work. You sure you don't see any other problems? –  Aug 04 '16 at 16:29
  • mysql_* functions have been removed from 7.0, and deprecated in previous versions. You should switch to PDO or mysqli to prevent future headaches. Without the error message, it's hard to tell what's wrong. – aynber Aug 04 '16 at 16:31
  • you need to remove all the single quotes around all the variables, including the one in this `$select_db = mysql_select_db('$dbname');` and pass the variable to it and see if that works `$select_db = mysql_select_db($dbname, $connection);` – Funk Forty Niner Aug 04 '16 at 16:31
  • @daveywavey42 Ping me with the @ symbol and followed by my name or anyone's name (no space between @ and the name) and that will send a messge to that person. So, ping me if you want to say if it worked or not. – Funk Forty Niner Aug 04 '16 at 16:38
  • You didn't put database for connection – jhony3 Aug 04 '16 at 17:12

0 Answers0