In the above diagram, part of the free software available from mysql.com, there are several key terms that you should understand before trying to use an SQL database server.
Examples of queries that search through an imaginary table named "test":PHP is usually compiled with access to MySQL database server. Functions like mysql_query(), mysql_connect(), mysql_error() are called an API (application programmer's interface) for MySQL. After specifying details like the username, password, and database name, a $conn variable is received from the function mysql_connect(). This permits us to send SQL queries to the server with code like:SELECT * FROM test WHERE last_name='Widenius'; SELECT * FROM test WHERE last_name='Widenius' AND first_name='Michael'; SELECT * FROM test WHERE last_name='Widenius' AND (first_name='Michael' OR first_name='Monty'); SELECT * FROM test WHERE last_name='Widenius' AND first_name >='M' AND first_name < 'N';These are examples of SQL (Structured Query Language). To use this language we either must be entering the directly into a piece of client software that speaks to the MySQL server OR we can use another language like PHP that is capable of contacting the MySQL server.With PHP, we send the above examples to the server (one by one!) with the mysql_query() function. It then returns a variable that can be used to investigate what happened. If there is no error, we can then use mysql_fetch_row() for as many rows as were returned for our query.
<?php $sql = "select name from artist where id = '$artistID';"; $result = mysql_query( $sql, $conn ) or die ( mysql_error() ); $artist = mysql_fetch_array( $result ); $artistName = $artist[name]; ?>