Steps to communicate with MySql database using PHP
If your PHP web application is dealing with a database most commonly MySql,The knowledge about the following functions and their order as described is better.
- mysql_connect(hostname,databaseUserName,databasePassword):This is the first function which will establish a connection with the database.It returns false on connection failure.
- mysql_select_db("databaseName","connectionName"):This function selects the database.It takes database name and connection name as parameter, Note that connection name is optional.This function can also return false in case of any error.
- mysql_query("sql"):After the connection is established and the database is selected successfully now we can talk with the database by using structured query language via mysql_query() function.This function returns the dataset on success or it can return false if the query was not executed due to some error.
- mysql_fetch_assoc(datasetRetrieved):This function iterate through the dataset which is retrieved as a result of mysql_query() function and gets the record one by one in the form of array.The PHP mysql_fetch_assoc () function mostly used in a while loop where each record is required to be extracted.
- mysql_num_rows(datasetRetrieved)This function takes the mysql_query() resulted dataset and return the number of rows this dataset has.
0 comments:
Subscribe to:
Post Comments (Atom)
Post a Comment