PHP MySQL Functions


preview imageProgramming
by Anurag Srivastava,Feb 12, 2018, 6:13:23 PM | 3 minutes |

PHP MySQL Functions

Here I will explain PHP functions for MySQL operations. For handling database connection and executing queries we use these functions.

mysql_connect()

  • The mysql_connect() function opens a non-persistent MySQL connection. 
  • mysql_connect(server,user,pwd )

mysql_pconnect()

The mysql_pconnect() function opens a persistent MySQL connection.

mysql_pconnect(server,user,pwd )

mysql_pconnect() is much like mysql_connect(), but with two major differences:

  • This function will try to find a connection that's already open, with the same host, username and password. If one is found, this will be returned instead of opening a new connection
  • The connection will not be closed when the execution of the script ends (mysql_close() will not close connection opened by mysql_pconnect()). It will stay open for future use

mysql_select_db()

The mysql_select_db() function sets the active MySQL database.

mysql_select_db(database,connection)

mysql_query()

The mysql_query() function executes a query on a MySQL database.

mysql_query(query,connection)

mysql_result()

The mysql_result() function returns the value of a field in a recordset.

This function returns the field value on success, or FALSE on failure.

mysql_result(data,row,field) // field optional

mysql_affected_rows()

The mysql_affected_rows() function returns the number of affected rows in the previous MySQL operation.

This function returns the number of affected rows on success, or -1 if the last operation failed.

mysql_num_fields()

The mysql_num_fields() function returns the number of fields in a recordset.

mysql_num_fields(data)

mysql_num_rows()

The mysql_num_rows() function returns the number of rows in a recordset.

mysql_num_rows(data)

mysql_insert_id()

The mysql_insert_id() function returns the AUTO_INCREMENT ID generated from the previous INSERT operation.

mysql_insert_id(connection)

mysql_error()

The mysql_error() function returns the error description of the last MySQL operation.

This function returns an empty string ("") if no error occurs.

mysql_error(connection)

mysql_fetch_array()

The mysql_fetch_array() function returns a row from a recordset as an associative array and/or a numeric array. 

This function gets a row from the mysql_query() function and returns an array on success, or FALSE on failure or when there are no more rows.

mysql_fetch_array(data)

mysql_fetch_assoc()

The mysql_fetch_assoc() function returns a row from a recordset as an associative array.

This function gets a row from the mysql_query() function and returns an array on success, or FALSE on failure or when there are no more rows.

mysql_fetch_assoc(data)

mysql_fetch_object()

The mysql_fetch_object() function returns a row from a recordset as an object.

This function gets a row from the mysql_query() function and returns an object on success, or FALSE on failure or when there are no more rows.

mysql_fetch_object(data)

mysql_fetch_row()

The mysql_fetch_row() function returns a row from a recordset as a numeric array.

This function gets a row from the mysql_query() function and returns an array on success, or FALSE on failure or when there are no more rows.

mysql_fetch_row(data)

mysql_fetch_lengths()

The mysql_fetch_lengths() function returns the length of the contents of each field in a row. 

mysql_fetch_lengths(data) 

mysql_field_name()

The mysql_field_name() function returns the name of a field in a recordset.Returns the field name on success, or FALSE on failure.

mysql_field_name(data,field_offset)

mysql_close()

The mysql_close() function closes a non-persistent MySQL connection.

mysql_close(connection)


Comments (0)

Leave a comment

Related Blogs

preview thumbnail
Introduction to Kibana

Aug 1, 2020, 6:19:45 PM | Anurag Srivastava

preview thumbnail
Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

preview thumbnail
Metrics Aggregations in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava

preview thumbnail
Introduction to Elasticsearch Aggregations

Aug 14, 2018, 4:47:56 PM | Anurag Srivastava

preview thumbnail
Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

preview thumbnail
Basics of Data Search in Elasticsearch

Aug 4, 2018, 7:02:21 AM | Anurag Srivastava

Top Blogs

preview thumbnail
Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

preview thumbnail
Elasticsearch REST APIs

Jul 31, 2018, 6:16:42 PM | Anurag Srivastava

preview thumbnail
preview thumbnail
Create a Chess board in PHP

Mar 9, 2020, 8:45:41 AM | Rocky Paul

preview thumbnail
Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

preview thumbnail
Metrics Aggregations in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava