I'm using Model and PHQL to update a record but mysql wont accept any changes. select and insert works properly.
sample update with PHQL:
UPDATE \Modules\Shared\Models\Airline SET [name] = 'test' WHERE id = '8'
|
Oct '15 |
6 |
752 |
0 |
Hey,
try with one of the examples here:
https://docs.phalcon.io/en/latest/reference/phql.html#updating-data
Same result...
Hey,
try with one of the examples here:
https://docs.phalcon.io/en/latest/reference/phql.html#updating-data
Simpled code i've used using model:
$object = Airline::findFirst($id);
$post = $this->request->getPost();
$object->name = $post['name'];
$object->lata = $post['lata'];
$object->language = $post['language'];
$object->parent_id = $post['parent_id'] ?: NULL;
$object->update();
foreach ($object->getMessages() as $m) {
echo $m. '<br>';
}
Model and db structure:
class Airline extends \Phalcon\Mvc\Model
{
/**
* @var integer
*/
public $id;
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $lata;
/**
* @var string
*/
public $language;
/**
* @var integer
*/
public $parent_id;
public function initialize()
{
$this->setSource('sh_airlines');
}
Could you provide sample code and db structure if that's not a problem?
Hi
Yes! I'm sure.
also post data was checked and are valid.
Hi,
are you sure that you've got a valid id for querying $object = Airline::findFirst($id);
Yes. $object rerturns a vaild object. save() has a same result..
ok,
does $object = Airline::findFirst($id); return a valid model object ?
Also try with
$object->save();
that's really strange.
Try to debug your sql save statement to see what happens during $object->save() (or update())
(https://docs.phalcon.io/en/latest/reference/models.html#logging-low-level-sql-statements)
oOOPS !
result:
[Mon, 26 Oct 15 17:00:52 +0330][INFO] UPDATE
sh_airlines
SETid
= ?,lata
= ?,language
= ?,parent_id
= ? WHEREname
= ?
is it normal?!
edit:
logging of Insert
also have question mark instead of values
[Mon, 26 Oct 15 21:07:37 +0330][INFO] INSERT INTO
sh_airlines
(name
,lata
,language
,parent_id
) VALUES (?, ?, ?, ?)
It is normal, this is params binding in PDO.
Can you try something like:
var_dump($object->update());
foreach ($object->getMessages() as $m) {
echo $m. '<br>';
}
exit;
This is from the first code box in your comment https://forum.phalcon.io/discussion/9131/phalcon-wont-update-record-anyway#C25077
note the exit after foreach loop;