I recently started learning PHP and found out that the general way to connect to the database is:
// create connection to database
$connection = mysql_connect("localhost", "root", "password")
// Select database
$db_select = mysql_select_db("myDB", $connection);
// and finally the query..
$result = mysql_query("SELECT * FROM table", $connection);
Now my question is: why should we use $ connection in the third step ?! since we use the database "myDB", I expect to write the third step as follows:
$result = mysql_query("SELECT * FROM table", $db_select);
but it seems that not the way it is done in php. can someone explain this why?
Nojan source
share