0

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());
}
Kevin G
  • 119
  • 1
  • 8
  • 1
    Possible duplicate of [Deprecated: mysql\_connect()](http://stackoverflow.com/questions/21797118/deprecated-mysql-connect) – LuFFy Mar 10 '17 at 08:33

2 Answers2

1

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

Falko
  • 3
  • 3
  • I have changed to msqli the connection is successful but when i try to use the connection to login i get this error: success Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\Login\process.php on line 12 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in C:\xampp\htdocs\Login\process.php on line 14 login not successful – Kevin G Mar 10 '17 at 08:46
  • it look like you did not use $con variable read document properly – Nishit Manjarawala Mar 10 '17 at 09:25
0

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();
    } ?>
Jordi Vicens
  • 696
  • 7
  • 17