mysql_query-executes query



mysql_query function  executes query on the default database, set using mysql_select_db() or by a previous query using mysql_db_query(), on the MySQL server connection referenced by connection . If no connection handle is specified in the connection argument, the last connection opened is used by default. If no connection is open, mysql_query() attempts to connect to a MySQL database by calling mysql_connect() without arguments.


The value returned depends on the query. SELECT, DESCRIBE, EXPLAIN, and SHOW queries return a MySQL result handle if successful and FALSE if they fail. Note that these types of queries are considered to have failed only if they're malformed. Other query types return TRUE on success and FALSE on failure.


To find the number of rows affected by a query:

mysql_num_rows() 
To set the default database:
mysql_select_db() 
To retrieve data from a query:
mysql_fetch_array() 
mysql_fetch_assoc() 
mysql_fetch_object() 
mysql_fetch_row() 
mysql_result() 
To query a specific database:
mysql_db_query() 
 
 

mysql_result() fetches a single field from a MySQL result set. The function accepts two or three arguments.

The first argument should be a MySQL result handle returned by mysql_db_query() or mysql_query().
The second argument should be the row from which to fetch the field, specified as an offset. Row offsets start at 0.

The optional last argument can contain a field offset or a field name. If the argument is not set, a field offset of 0 is assumed. Field offsets start at 0, while field names are based on an alias, a column name, or an expression.