I am trying to restore a subset of data from a backup table to a current
table. I have the following code:
$db = $this->_registry->get('db');
$select = $db->select();
$select->from(array('backupUsers'));
if($name= $request->getItem('name')){
$select->where('name = ' . $db->quote($name));
}
if($surname= $request->getItem('surname')){
$select->where('surname= ' . $db->quote($surname));
}
$deleteQuery = "DELETE FROM users WHERE user_id IN (" . $select . ")";
$insertQuery = "INSERT INTO users" . $select;
$db->beginTransaction();
try {
$result = $db->query($deleteQuery);
$result->execute();
$db->query($insertQuery);
$result->execute();
$db->commit();
}catch (Exception $e){
echo $e->getMessage();
$db->rollBack();
}
this code looks in the current table for any pk's that exist in the backup
table, and deletes those rows from the current table. It then inserts the
data from the backup table into the current table. The deletion of the row
from the current table first is to avoid pk conflicts.
This produces valid sql which works when run through phpMyAdmin, but from
php i get the following error:
Cardinality violation: 1241 Operand should contain 1 column(s)
What does this mean? Is there anything wrong with the above?
--
View this message in context: http://www.nabble.com/Cardinality-Violation---executing-queries-tp18772524p18772524.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论