Advertisement

05.15.2008 at 08:53PM PDT, ID: 23407351 | Points: 500
[x]
Attachment Details

php upgrade - now must set PDO attribute - why?

Asked by gothamww in PHP Scripting Language, PHP Installation

Tags: php, all browsers, php configuration, PDO

Hi,

My host upgraded php on my server, and my site died.  Through trial and error, I found out that my calls to

$dbh->prepare("DESCRIBE xxxx");

were generating an error:

General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.'

Before I start trying to figure out what has changed in the installation that would make this an issue all of a sudden - can anyone tell me what this means?  I've set the attribute referred to above, but what is the query buffer?  why do I need to set this to true?

Here's the code:

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
class DBTable {
        
        private $aDBFields;
        private $aAutoPrimaryField;
        private $aPrimaries;
        private $aData;
        private $table;
 
        function __construct($table,$aData = NULL) {
            global $dbh;
            // first get the list of fields in the database.  You can use this array in your methods to constrain the fields that can be used in insert and update statements.
            $sth = $dbh->prepare("DESCRIBE $table");
            $sth->execute();
			if( $sth->columnCount() ) { 
				while($aRow = $sth->fetch(PDO::FETCH_ASSOC)) {
					$this->aDBFields[] = $aRow['Field'];
					if( $aRow['Extra'] == 'auto_increment' ) {
						$this->aAutoPrimaryField = $aRow['Field'];
					}
					if( $aRow['Key'] == 'PRI' ) {
						$this->aPrimaries[] = $aRow['Field'];
					}
				}
				
				// now store the data passed to the constructor
				if( !is_null($aData) ) {
					foreach($aData as $key => $value) {
						$this->aData[$key] = $value;
					}
				}
				$this->table = $table;
			} else {
                throw new Exception( 'MySQL Error: no such table as '.$table);
			}
        }
 
etc...
[+][-]05.16.2008 at 04:08AM PDT, ID: 21581712

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 07:33AM PDT, ID: 21583076

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628