Examples of non-cached queries for buffered and unbuffered queries and PDO in MySQL

Source: Internet
Author: User
Tags mysql query

MySQL Buffered and unbuffered queries

Today we are going to talk about the advanced function of MySQL query cache, that is, query cache and query non-cache!

Cause: (Memory overflow warning)

PHP Fatal error:allowed Memory size of 268 435 456 bytes Exhausted

1. Official

The main saying is that the cache query is all at once to find out the contents, put in memory, will accumulate more, but not the cache query directly from the MySQL server is returned, that is, waiting for the PHP process to get the next data. (mainly understand the meaning of the line, want to fully understand, micro-I or Baidu translation)

2.Buffer and Unbuffer Query

A) cache query is generally used for querying data once obtained, will be stored in memory;

b) A non-cached query is returned directly from a single piece of MySQL and is not stored in memory;

3.mysqli,pdo non-Cached query examples

<?php# #mysqli $mysqli = new mysqli ("localhost", "My_user", "My_password", "World");    $uresult = $mysqli->query ("Select Name from City", Mysqli_use_result); if ($uresult) {while ($row = $uresult->fetch_assoc ()) {echo $row [' Name '].       Php_eol;    }} $uresult->close ();    # #pdo $pdo = new PDO ("Mysql:host=localhost;dbname=world", ' my_user ', ' my_pass ');    $pdo->setattribute (Pdo::mysql_attr_use_buffered_query, false);    $uresult = $pdo->query ("Select Name from City"); if ($uresult) {while ($row = $uresult->fetch (PDO::FETCH_ASSOC)) {echo $row [' Name '] .          Php_eol;    }}# #mysql will be discarded, understand the next $conn = mysql_connect ("localhost", "My_user", "My_pass");    $db = mysql_select_db ("World");    $uresult = Mysql_unbuffered_query ("Select Name from City"); if ($uresult) {while ($row = Mysql_fetch_assoc ($uresult)) {echo $row [' Name ']. Php_eol;          }    } 

Summarize:
The cache queries and non-cached queries here, in effect, are cached queries that cause a memory overflow when manipulating large amounts of data, and you can use non-cached queries to prevent this from happening, but at this point you have to be aware that MySQL will wait for the PHP program to get the data until all the data has been retrieved. So it will consume MySQL performance, then how do we use them correctly, we have to specifically grasp the core, memory overflow, MySQL performance consumption, the 2 grasp well, know what to use in the scene, if you do not know how to use, you can leave a message or micro me!

Related articles:

How MySQL ' queries ' and ' questions ' is measured

How to find and kill misbehaving MySQL queries

Related videos:

Hanshunping 2016 latest MySQL Basics video tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.