Thursday, November 25, 2004

MySQL Function List

Mostly used functions
mysql_connect(dbhost, username, password)
Open a connection to a MySQL Server
mysql_select_db(dbname)
Select a MySQL database
mysql_query(sqlstmt)
Send a MySQL query
mysql_fetch_array(query result, [MYSQL_ASSOC/MYSQL_NUM/MYSQL_BOTH])
Fetch a result row as an associative array, a numeric array, or both.
mysql_close()
Close MySQL connection
mysql_error()
Returns the text of the error message from previous MySQL operation
mysql_free_result (query result)
Free result memory
Sample code
mysql_connect("localhost", "mysql_user", "mysql_password") or
die(
"Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while (
$row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("ID: %s Name: %s", $row["id"], $row["name"]);
}

mysql_free_result($result);

Full php mysql function list

No comments: