0

I'm trying to use the zend framework update class: http://framework.zend.com/manual/2.2/en/modules/zend.db.sql.html#zend-db-sql-update

to create something like the statement found here:
http://dev.mysql.com/doc/refman/5.0/en/update.html

UPDATE items,month SET items.price=month.price WHERE items.id=month.id;

I've tried passing an array to ->table but it fails on the string conversion.

// UPDATE `Array`
$update->table(['table1', 'table2']) 

I've tried creating an escaped string but it ends up double escaped when converted to sql.

// UPDATE ``table1`,`table2``
$update->table("`table1`,`table2`")

I've tried cheating and used implode to use the glue the tables together

// UPDATE `table1``,``table2`
$update->table(implode("`,`", ['table1','table2']))

Does anyone have a clean answer to this issue?

metric152
  • 422
  • 4
  • 16

2 Answers2

0

After further research, I don't think it can be done. The reason I say that is because the query you've proposed may be too resource intensive. After looking for an alternate option, I've come across Update one MySQL table with values from another. However, that I'm aware of, there's no join option on an Update object. So at least at this stage, I don't believe it can be done.

Community
  • 1
  • 1
Matthew Setter
  • 2,397
  • 1
  • 19
  • 18
0

Are you trying to write sql like: "update tableOne, tableTwo set ...." !! I do not think it is possible in sql. As this kind of syntex not supported by mySql so do zend. here is zend table method-

public function table($table)
@param  string|TableIdentifier $table

parameter is simply string or TableIdentifier. So you have to write two sql in zend

$update->table('table1');
$update->set(array('foo' => 'bar', 'baz' => 'bax'));
.......
........
$update->table('table2');
$update->set(array('foo1' => 'bar', 'baz1' => 'bax'));

Hope it will help you.

Atiqur
  • 3,802
  • 1
  • 25
  • 26
  • The linked example at the top of the question shows the same sql statement on the mysql documentation. The query does work but I'm trying to use the Update class. I'm currently writing it by hand using database->query. I tried digging around the code and saw the function you're talking about. It only accepts one table. I was hoping there was a way around this. – metric152 Sep 01 '14 at 03:57