Problems with the PDO of PHP

Source: Internet
Author: User
 M_pdo = new PDO (' Mysql:host=127.0.0.1;dbname=mydb ', ' root ', ' 123456 ', array (Pdo::mysql_attr_init_command = = "SET            NAMES ' UTF8 '; "));        return true;        } catch (Pdoexception $e) {return false;        }} public function Close () {$this->m_stmt = null;    $this->m_pdo = null;        Public Function prepare_statement ($prepare _statement_text) {if (Empty ($this->m_pdo)) return;        if (!empty ($this->m_stmt)) {$this->m_stmt->closecursor ();    } $this->m_stmt = $this->m_pdo->prepare ($prepare _statement_text);        Public Function Set_param ($param _name, $param _value) {if (Empty ($this->m_stmt)) return;    $this->m_stmt->bindparam ($param _name, $param _value);        Public Function Execute_single_row () {if (Empty ($this->m_stmt)) Return to self:: $empty _array; if (! $this->m_stmt->execute ()) {return self:: $empTy_array;    } return $this->m_stmt->fetch (PDO::FETCH_ASSOC);        Public Function Execute_rows () {if (Empty ($this->m_stmt)) Return to self:: $empty _array;            if (! $this->m_stmt->execute ()) {$error = $this->m_stmt->errorinfo ();        Return self:: $empty _array;        } $this->m_stmt->setfetchmode (PDO::FETCH_ASSOC);    return $this->m_stmt->fetchall ();  }}class Tcategoryattrdb extends abstractdb{public function get_category_attr_list ($arr _params) {$sql = ' Select Category_id,category_name,attrib_name,attrib_content from cat_attrib where category_id =: category_id and is_delete = 0 '        ;        $this->prepare_statement ($sql);        $this->set_param (': category_id ', $arr _params[' category_id ']);    return $this->execute_rows (); Public Function getcategoryidfromtcategory ($arr _params) {$sql = ' SELECT category_id from ' T_category ' where C Ategory_name =: CAtegory_name and Is_delete = 0 and parent_id = (SELECT category_id from t_category WHERE category_name =:p aren        T_category_name and is_delete = 0); ';        $this->prepare_statement ($sql);        $this->set_param (':p arent_category_name ', $arr _params[' parent_category_name ']);        $this->set_param (': Category_name ', $arr _params[' category_name ']);    return $this->execute_single_row (); }} $t _db = new Tcategoryattrdb (), $arr _params = Array (' parent_category_name ' = ' XXXX ', ' category_name ' = ' YYY '); if ($t _db->open ())    {$category = $t _db->getcategoryidfromtcategory ($arr _params); $result = $t _db->get_category_attr_list ($category);}? >


The code above is the key code I extracted, on my development machine, when executing the second SQL prepare () method will return false instead of the Pdostatement object, errorinfo output information is: Cannot execute queries While other unbuffered queries is active. Consider using Pdostatement::fetchall (). Alternatively, if your code is a ever going to run against MySQL, you may enable query buffering by setting the Pdo::my Sql_attr_use_buffered_query attribute. "
But this code in the production environment is not a problem, I tried to solve the problem of my development machine with the following methods are successful, as follows:
(1) Set the Mysql_attr_use_buffered_query property at PDO initialization, pdo::mysql_attr_use_buffered_query=>1//(2) in Prepare_ Add the following code to the statement function, which is to execute closecursor () if (!empty ($this->m_stmt)) {$this->m_stmt->) before prepare    Closecursor ();}

Now there are a few doubts to ask:
1. My PHP version is 5.2.10, the production environment PHP version is 5.3.11, but what is the difference between the results of this inconsistency? Is it a PHP version?
2.pdo::mysql_attr_use_buffered_query (available in MYSQL): Use BUFFERED queries. This is the document's interpretation of the property, but it's not quite clear. What is called a cache query, what is the cached object, how much memory to use, and what the size of the footprint is related to.
3. How big is the effect of adding pdostatement::closecursor on performance (when concurrency is high)?


Reply to discussion (solution)

PHP is the difference! After all, it's getting better.
PDO is designed to be a single-user approach, and should be read after each query to reuse objects

PHP is the difference! After all, it's getting better.
PDO is designed to be a single-user approach, and should be read after each query to reuse objects
Do you mean that after version 5.3, you don't need closecursor to be able to reuse statement?

Yes!

Your production environment is already 5.3.11, then why is your development environment still 5.2.10?
Is it not possible to play a php5.3 advantage? (At least php5.3 is 5 times times faster than php5.2, php5.4 is 10 times times faster than php5.3)

Yes!

Your production environment is already 5.3.11, then why is your development environment still 5.2.10?
Is it not possible to play a php5.3 advantage? (At least php5.3 is 5 times times faster than php5.2, php5.4 is 10 times times faster than php5.3)
Project is a new handover, the original project has been 5.2.10, and not willing to change the development machine ~ ~
Question 2,3 can you answer it?

  • 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.