![]() |
|
PHP built-in MySQL functions. Free online PHP and MySQL Web Database Programming Tutorial... |
| Lessons | PHP Built-In MySQL Functions |
|
|
mysql_connect() The mysql_connect() function opens a connection to the MySQL database server. It needs has three parameters namely; server name, username, and password. Its syntax follows: $connection = mysql_connect("servername","username","password"); mysql_select_db() The mysql_select_db() function is used to select an existing database on the MySQL server for subsequent use by the PHP script. It requires two arguments; database name and a valid reference to the MySQL database server. Its syntax follows: $db = mysql_select_db("myDB", $connection); mysql_query() This function is used to execute SQL commands and statements. It requires an open connection to the database. Its syntax follows: $sql_result = mysql_query("SELECT * FROM SOMETABLE", $connection); mysql_error() The mysql_error() function returns a meaningful error message when something goes wrong with our connection or query. Generally it is used in the context of the die() function. Its syntax follows: $sql_result = mysql_query("SELECT * FROM SOMETABLE", $connection) or die(mysql_error()); mysql_fetch_array() This function is used to get a record from the recordset in the form of an array. Its syntax follows: $row = mysql_fetch_array($sql_result); mysql_num_rows() This function is generally used to get the number of rows in a result set. Its syntax follows: $num = mysql_num_rows($sql_result);
Next: PHP MySQL ODBC 1
|