Php problem

Parse error: syntax error, unexpected ‘$db’ (T_VARIABLE) in /home/u109924092/public_html/student/config.php on line 3

<?php $conn=mysqli_connect("localhost","Student","")or die("Connection to Server failed"); $db=mysql_select_db("Student",$conn)or die("Connection to Database failed"); ?>

What happens if you write this as an expression, …?

$db = { fn(...) or die(...) };
1 Like

In order to select and query a specified database, you should do something like this:

<?php
    $con = new mysqli($host, $user, $pass, $db, $port) or die("Unable to connect");
    $str_table= "SELECT  * FROM $table_name ";
    $db = mysqli_query($con, $str_table) or die("Unsuccessfull Query");
?>

Notice how I selected the database using the $db (database name) field on my $con (connection) variable.

More examples can be found here for PHP 7 or above.

2 Likes