Queries upon the database can be made once a connection to the database server has been established and a specific database has been selected.


This is performed by sending a query as a parameter into the mysql_query() function, that returns a result set which is assigned to an array variable:


$query = 'SELECT * FROM customers' ;  //where customers is the table being queried


$resultSetmysql_query( $query, $connection ) ;



	$connection = mysql_connect( $server, $user, $passwd ) ;

	if( ! $connection ) {

		die('Error connecting to the database:' . mysql_error() ) ;

	mysql_select_db('Academy') ;

	$query = 'SELECT * FROM customers' ;

	$resultSet = mysql_query( $query );

	if( ! $resultSet){

		die('Error getting result set: ' . mysql_error() ) ;

	mysql_close( $connection ) ;


In this example, the result set is now ready to be viewed / acted upon.


Alternative queries to INSERT, UPDATE or DELETE data are also carried with the mysql_query() function.

Leave a Reply