-1

So trying to make a database with php, however if I run my code I get just blank pages in both Firefox and Chrome?

Is there something I have to do in order to make php work?

    <html>
<head>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

mysql_close($con);
?>


</body>
</html>
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Ausghostdog
  • 178
  • 1
  • 3
  • 13

1 Answers1

2

Use mysqli_connect(). Don't use mysql_* functions, they are deprecated as of PHP 5.5 and are removed.

Try below.

<?php
$con=mysqli_connect("localhost","root","");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

if (mysqli_query($con,"CREATE DATABASE my_db1"))
  {
  echo "Database created";
  }


mysqli_close($con);
?>
RJParikh
  • 4,096
  • 1
  • 19
  • 36