PHP: mysql_query and it's connection explanation
database-connection, mysql, php
Solution
The connection represents a database server session, which maintains the database state for you. The currently selected database is simply one part of a session's state, so by passing the connection you are implicitly also passing the currently selected database (along with various other necessary information). In other words, the connection is more general than the selected database.
(As others have already noted, it isn't necessary to explicitly pass the connection when your program only needs to access a single database on a single server. MySQL will use the most recently connected session by default.)
Problem
I recently started to learn PHP and found out that the common way to connect to a 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 we have to use $connection in third step ?! as we are using "myDB" database I expect to write the third step this way : ``` // and finally the query.. $result = mysql_query("SELECT * FROM table", $db_select); ``` but it seems, that's not how it's done in php. can somebody explain it why ?