Fatal error on line xx php

I am new to php.I have a php file that tries to connect to an sql database.The database name is student.

index.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Available</title>
    </head>
    <body>
    <?php 
        $host="127.0.0.1";
        $port=3306;
        $socket="";
        $user="root";
        $password="aPassword";
        $dbname="student";

        $con = new mysqli($host, $user, $password, $dbname, $port, $socket)
            or die ('Could not connect to the database server' . mysqli_connect_error());
        if($con){
            echo "Connection to server  working";
        }
        else{
            echo "You ruin my life";
        }
        //$con->close();

     ?>
    </body>
</html>

However if I try to run this file I get the following error:

Fatal error: in index.php on line 17
Line 17 is this:

$con = new mysqli($host, $user, $password, $dbname, $port, $socket)
                or die ('Could not connect to the database server' . mysqli_connect_error());

Any Ideas?
I forgot to mention that the code is generated by MySql workbench


Source: stackoverflow-php