PHP Function: Built-in Functions part 3
Welcome back to the not so exciting built in functions part 3!
Today we will deal with Database Connectivity Functions for MySQL.
*Numerous PHP functions exist for connecting to adn querying a MySQL server. Following are some basic functions and their syntax.*
mysql_connect()
This function opens a connection to MySQL. It requires a server name, username and password.
$connection = mysql_connect(“servername”, “username”, “password”);
mysql_create_db()
This function creates a database on the MySQL server. It requires a valid established connection.
mysql_create_db(“DBName”);
mysql_drop_db()
This function drops a database on the MySQL server. It requires a valid established connection.
mysql_drop_db(“DBName”);
mysql_select_db()
This function selects a database on the MySQL server for use by subsequent queries. It requires a valid established connection.
$db = mysql_select_db(“DBName”, $connection);
mysql_query()
This function issues the SQL statement. It requires an open connection to the database.
$sql_result = mysql_query(“SELECT * FROM SOMETABLE”,$connection);
mysql_error()
This function returns a meaningful error message when something goes wrong with your connection or query. It’s usually used in the context of die() function like this:
$sql_result = mysql_query(“SELECT * FROM SOMETABLE”, $connection) or die(mysql_error));
mysql_fetch_array()
This function auto. places the SQL statement reult row into an array.
$row = mysql_fetch_array($sql_result);
mysq_num_rows()
This function returns the number of rows in a result set.
$num = mysql_num_rows($sql_result);
mysql_free_result()
This function frees the memory resources used by a database query.
mysql_free_result($sql_result);
mysql_close()
This function explicitly closes a database connection.
mysql_close($connection);
That concludes todays show of Built-in Functions part 3. Next php function: Built-in Functions part 4