This code works correctly!
$con=mysqli_connect("localhost","root","","laboratory");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM test");
while($row = mysqli_fetch_array($result))
{
echo $row['name'];
echo "<br>";
}
mysqli_close($con);
But when I remove database_name from mysqli_connect I would use the mysql_select_db, the following error occurs "Warning: mysql_select_db() expects parameter 2 to be resource, object given in"
Code after change:
$con=mysqli_connect("localhost","root","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$db_selected = mysql_select_db("laboratory", $con);
if (!$db_selected)
{
die ("Can\'t use laboratory : " . mysql_error());
}
$result = mysqli_query($con,"SELECT * FROM test");
while($row = mysqli_fetch_array($result))
{
echo $row['name'];
echo "<br>";
}
mysqli_close($con);