-1

I have problems with MySQL in my PHP code

$konek= mysql_connect('localhost','root',' ');
if ($konek)

so, I cannot connect it to my DB and the mysql_connect is lined in the code like this picture. enter image description here

mysql_connect is deprecated

What's wrong with MySQL in my code? Thanks

Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
Ayam Geprek
  • 151
  • 2
  • 18

1 Answers1

4

Use this

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>
Farhan Ali
  • 230
  • 3
  • 14
  • 1
    You should also note that this won't mix or interchange with other APIs, and that this library supports prepared statements, which should always be used for any variable input. – Qirel Feb 18 '19 at 05:48