PHP MySQL Functions
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
Introduction to Kibana
Aug 1, 2020, 6:19:45 PM | Anurag Srivastava
Bucket Aggregation in Elasticsearch
Aug 29, 2018, 7:15:06 PM | Anurag Srivastava
Metrics Aggregations in Elasticsearch
Aug 18, 2018, 6:02:20 PM | Anurag Srivastava
Introduction to Elasticsearch Aggregations
Aug 14, 2018, 4:47:56 PM | Anurag Srivastava
Wildcard and Boolean Search in Elasticsearch
Aug 10, 2018, 7:14:40 PM | Anurag Srivastava
Basics of Data Search in Elasticsearch
Aug 4, 2018, 7:02:21 AM | Anurag Srivastava
Top Blogs
Wildcard and Boolean Search in Elasticsearch
Aug 10, 2018, 7:14:40 PM | Anurag Srivastava
Elasticsearch REST APIs
Jul 31, 2018, 6:16:42 PM | Anurag Srivastava
How to count number of words in a HTML string and find Read time in Python 3
Jun 30, 2018, 12:07:47 PM | jitender yadav
Create a Chess board in PHP
Mar 9, 2020, 8:45:41 AM | Rocky Paul
Bucket Aggregation in Elasticsearch
Aug 29, 2018, 7:15:06 PM | Anurag Srivastava
Metrics Aggregations in Elasticsearch
Aug 18, 2018, 6:02:20 PM | Anurag Srivastava