Php Mysql

(PHP 4, PHP 5)

PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database. What you should already have? You have gone through MySQL tutorial to understand MySQL Basics. Downloaded and installed a latest version of MySQL.

mysql_free_resultFree result memory


This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0.Instead, the MySQLi or PDO_MySQL extension should be used.See also MySQL: choosing an API guide.Alternatives to this function include:

MySQL works very well in combination of various programming languages like PERL, C, C, JAVA and PHP. Out of these languages, PHP is the most popular one because of its web application development capabilities. MySQL Database MySQL Connect MySQL Create DB MySQL Create Table MySQL Insert Data MySQL Get Last ID MySQL Insert Multiple MySQL Prepared MySQL Select Data MySQL Where MySQL Order By MySQL Delete Data MySQL Update Data MySQL Limit Data PHP XML PHP XML Parsers PHP SimpleXML Parser PHP SimpleXML - Get PHP XML Expat PHP XML DOM PHP - AJAX. Create json Object by php from mysql result-1. Create php key and value array. How can i print a database query to a javascript array? How to convert to JSON. How do I return an sql result with ajax in JSON format. What is to be done, to add JSON CODE to php code? Can you please edit my code given below. I am very new to coding. Welcome to the PHP & MySQL Certification Course for Beginners. This course offers a comprehensive guide to learning how to code in PHP. We also explore integrating MySQL Databases into your PHP Projects for dynamic, user driven functionality. We start with PHP basics, including variable declaration and data output.

  • Assign the value of null to the PDO object, or PDOStatement::closeCursor()


mysql_free_result() will free all memory associated with the result identifier result.

mysql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script's execution.



The result resource thatis being evaluated. This result comes from a call tomysql_query().

Return Values

Returns true on success or false on failure.

If a non-resource is used for the result, an error of level E_WARNING will be emitted. It's worth noting that mysql_query() only returns a resource for SELECT, SHOW, EXPLAIN, and DESCRIBE queries.


Php Mysql

Example #1 A mysql_free_result() example

= mysql_query('SELECT id,email FROM people WHERE id = '42');
if (!
$result) {
'Could not run query: ' . mysql_error();
/* Use the result, assuming we're done with it afterwards */
$row = mysql_fetch_assoc($result);
/* Now we free up the result and continue on with our script */


Note: Plex server setup url.


For backward compatibility, the followingdeprecated alias may be used: mysql_freeresult()

See Also

  • mysql_query() - Send a MySQL query
  • is_resource() - Finds whether a variable is a resource
webmaster at bluesting dot co dot za
10 years ago
mysql_query() also returns a resource for 'OPTIMIZE TABLE' statements!
admin at ifyouwantblood dot de
13 years ago
yes this function may increase the memory usage if you use unbuffered querys and if you have not fetched all the data from mysql. in this case the mysql api has a problem: you want to free the result but do not want to close the connection. now mysql will only accept another query if all data has been fetched, so the api now must fetch the rest of the data when calling mysql_free_result().
so only use unbuffered querys if you fetch all the data (and need it).
14 years ago
If you're seeing warnings like 'Warning: Unknown: 6 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in Unknown on line 0' and want to turn them off, set mysql.trace_mode = Off in your php.ini
  • MySQL Functions

Summary: in this tutorial, you will learn how to query data from MySQL database by using PHP PDO. You will also learn how to use PDO prepared statement to select data securely.

PHP MySQL Querying data using simple SELECT statement

To query data from the MySQL database, follow the steps below:

First, connect to a MySQL database. Check it out the connecting to MySQL database using PDO tutorial for detail information.

Then, construct a SELECT statement and execute it by using the query() method of the PDO object.

The query() method of the PDO object returns a PDOStatement object, or false on failure.

Next, set the PDO::FETCH_ASSOC fetch mode for the PDOStatement object by using the setFetchMode() method. The PDO::FETCH_ASSOC mode instructs the fetch() method to return a result set as an array indexed by column name.

After that, fetch each row from the result set until there is no row left by using the fetch() method of the PDOStatement object.

Putting it all together.


PHP MySQL Querying data using PDO prepared statement

In practice, we often pass the argument from PHP to the SQL statement e.g., get the employee whose last name ends with son . To do it securely and avoid SQL injection attack, you need to use the PDO prepared statement.

Php Mysql Tutorial

Let’s take a look at the following example:

How the script works.

  • First, we use a question mark (?) in the SELECT statement. PDO will replace the question mark in the query by the corresponding argument. The question mark is called positional placeholder.
  • Next, we call the prepare() method of the PDO object to prepare the SQL statement for the execution.
  • Then, we execute the statement by calling the execute() method of the PDOStatement object. In addition, we pass an argument as an array to replace the placeholder in the SELECT statement. By doing this, the SELECT statement will be translated as follows:
  • After that, we set the fetch mode for the PDOStatement object.
  • Finally, we fetch each row of the result set and display the last name field.

PHP provides you with another way to use placeholders in the prepared statement called named placeholder. The advantages of using the named placeholder are:

  • More descriptive.
  • If the SQL statement has multiple placeholders, it is easier pass the arguments to the execute() method.

Let’s take a look at the following example:

The :lname and :fname are the named placeholders. They are substituted by the corresponding argument in the associative array that we pass to the execute method.

Php Mysql Select

In this tutorial, you have learned how to query data from the MySQL database using PDO objects.