PHP Function Mysql_Select_DB
The php function mysql_select_db is used to select database for MySQL functions. It is a very useful function and can be used for many different purposes. In this article we will take a look at some examples of how to use the mysql_select_db function.
Using the mysql_select_db() function we will be able to select the database that we want to work with and that will become our default database for table references that do not include an explicit database specifier. The function returns zero if it is successful or nonzero if an error occurs.
Before we can use the mysql_select_db() we must first create a database connection in PHP. The easiest way to do this is to use the PDO_MySQL or mysqli extension instead of the old mysql extension which will stop working in PHP 7. This will allow you to easily upgrade your code to the newer version of PHP without any problems.
When creating a MySQL connection we must pass in the host, user name, password and database name. The host can be either a localhost or an IP address. The user name and password must be a valid user in the MySQL database. The database name is the name of the database where operations will be performed.
After we have created the database connection we can then run SQL queries to retrieve data from the database. For example if we wanted to get the data from the employee table we would do a query like "SELECT * FROM employee". After retrieving the data we can then display it on our website.