PHP & MySQL on i6.cims.nyu.edu

Commonly used PHP functions for use with MySQL (and class discussion!):

PHP (listing both “mysql” and “mysqli”) Procedural Functions Task
mysql_connect ($server-name, $user-name, $password)

mysqli_connect ($localhost, $user-name, $user-password, $database)

attempts to open a connection to a mysql server
mysql_select_db ($database-name,$link-identifier)

mysqli_select_db($link-identifier, $database-name);

sets the current active database
mysql_fetch_array ($result)

mysqli_fetch_array( $result )

returns an array that corresponds to a table row; this is typically used with a while loop
mysql_num_rows ($result)

mysqli_num_rows($result)

returns the number of table rows in a result
mysqli_real_escape_string($link-identifier,$string) returns a string which has inappropriate characters escaped; this also helps to protect against SQL injections (attacks)
mysql_query (SQL-query-string, link-identifier)

mysqli_query($link, $query)

submits a query to the currently active database
mysql_free_result($result)

mysqli_free_result($result)

after using a result, free up the memory
mysql_close(link-identifier)

mysqli_close(link-identifer);

close the connection