Open a connection to a MySQL Server
Select a MySQL database
Send a MySQL query
Fetch a result row as an associative array.
Fetch a result row as an associative array, a numeric array, or both.
Get the ID generated from the previous INSERT operation.
Get number of affected rows in previous MySQL operation
Get a result row as an enumerated array
Get number of rows in result
Close MySQL connection
Returns the text of the error message from previous MySQL operation.
Fetch rows from a result-set, then free the memory associated with the result. No return value.
<?php $link = mysql_connect('host_name', 'user_name', 'password')or die('Could not connect: ' . mysql_error()); // connecting, selecting database echo 'Connected successfully'; mysql_select_db('database_name') or die('Could not select database'); $query = 'SELECT * FROM table_name'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // performing SQL query // Printing results in HTML echo "\n"; while($row = mysql_fetch_assoc($result )){ echo "\t\n"; foreach ($row as $col_value) { echo "\t\t\n"; echo "$col_value\n"; } echo "\t\n"; } mysql_free_result($result); // Free resultset mysql_close($link); // Closing connection ?>