Think this should be an easy one. I understand how to establish a connection, eg:
$con = mysql_connect("localhost","peter","abc123");
Where localhost is the database type, peter is the user and abc123 the password but how do you specify the actual database? For example, I have 3 databases on my server. How do I specify database2?
As there are so many answers that suggest
mysql_select_db('database1');and its getting more upvotes I’ll try to create a complete answer:Don’t use
mysql_select_db('database1');!(You should not use it in new development projects because it is in deprecation process)
Use one of the following ways:
Either you use PDO like this:
Or you could use mysqli: