Jump to content

Fatal error: Cannot execute queries while other unbuffered queries are active


Recommended Posts

Bonjour,

 

Je suis en train de développer un module et je suis face à un soucis que je rencontre pour la première fois (PS1.5).

 

Voici ma fonction :


function addToForm($id_type, $label="New label", $value="", $required="0", $validate="", $other_attr="", $field_class="", $display_label="1", $id_edit=false){
	global $ukoo_form;
	$output='';
	if(!$id_edit){
		$position = Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'ukoo_form_field`;', false);
		$sql = '
			INSERT INTO `'._DB_PREFIX_.'ukoo_form_field` (id_type, label, value, class, other_attr, required, validate, display_label, position)
			VALUES ('.(int)$id_type.', "'.addslashes($label).'", "'.addslashes($value).'", "'.addslashes($field_class).'", "'.addslashes($other_attr).'", "'.(int)$required.'", "'.addslashes($validate).'", "'.(int)$display_label.'", '.(int)$position.');
		';
	}else{
		$sql = '
			UPDATE `'._DB_PREFIX_.'ukoo_form_field`
			SET label = "'.addslashes($label).'", value = "'.addslashes($value).'", class = "'.addslashes($field_class).'", other_attr = "'.addslashes($other_attr).'", required = "'.(int)$required.'", validate = "'.addslashes($validate).'", display_label = "'.(int)$display_label.'"
			WHERE id_field = "'.(int)$id_edit.'";
		';
	}
	if(Db::getInstance()->execute($sql)){
		$output.='<li id="field_'.(!$id_edit?Db::getInstance()->Insert_ID():$id_edit).'">'.$this->previewField((!$id_edit?Db::getInstance()->Insert_ID():$id_edit), false).'</li>';
	}else{ $output.= 'NOK'; }
	echo $output;
}

 

et voici l'erreur qui s'affiche dans mon BO Prestashop 1.5 :

 

Fatal error: Uncaught exception 'PrestaShopDatabaseException' with message '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.

			INSERT INTO `ps_ukoo_form_field` (id_type, label, value, class, other_attr, required, validate, display_label, position)
			VALUES (1, "tesf", "", "", "", "0", "", "1", 8);

' in /var/www/vhosts/xxxxxxx/httpdocs/classes/db/Db.php:603 Stack trace: #0 /var/www/vhosts/xxxxxxx/httpdocs/classes/db/Db.php(308): DbCore->displayError('?????INSERT INT...') #1 /var/www/vhosts/xxxxxxxx/httpdocs/classes/db/Db.php(448): DbCore->query('?????INSERT INT...') #2 /var/www/vhosts/xxxxxxxxx/httpdocs/modules/ukoo_form/ukoo_form.php(593): DbCore->execute('?????INSERT INT...') #3 /var/www/vhosts/xxxxxxxxx/httpdocs/modules/ukoo_form in /var/www/vhosts/xxxxxxxxx/httpdocs/classes/db/Db.php on line 603

 

Or je ne trouve aucun renseignement sur l'utilisation de PDO dans la doc PrestaShop. Il est d'ailleur à peine mentionné dans la doc officielle.

 

Est-ce que quelqu'un aurait une piste pour moi ?

 

Merci d'avance ! ;)

Link to comment
Share on other sites

Alors pour info, j'ai pu repousser le problème en modifiant la ligne suivante :

$position = Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'ukoo_form_field`;', false); 

Par :

$position = 9999;

 

Mais ce n'est que temporaire, je cherche toujours une VRAIE solution. Alors si vous avez une idée je suis preneur.

  • Like 1
Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...