kheang
(Ken)
June 27, 2011, 1:41pm
1
Hi,
I have done the following and can’t figure out why the result is like this.
I am saving some data into a table.
I am doing the following method.
$model = new Tbl_Orders;
$model->id_customer = $this->id_customer;
$model->save();
It should return the auto incremented value in $model->order_no;
My problem is when I echo that value right after the save, it returns 1, 2, 3, etc.
It should return 00000001, 00000002, 00000003, etc.
When I load the values using findByPk and echo that field, it returns it correctly.
Is this normal behavior?
zaccaria
(Matteo Falsitta)
June 27, 2011, 2:30pm
2
I think that there is not a big difference.
The autoincrement field should be an int, isn’t it? Therefore what for you need all this zeros?
kheang
(Ken)
June 27, 2011, 2:38pm
3
I am using it to display an order number.
nguyendh
(Duynguyen0511)
June 27, 2011, 3:21pm
4
So you set id_customer columns as INT( and you expect to get 00000001 instead of 1 ? Interesting, I haven’t thought about this. Btw, Have you solved your issue ? Please share
kheang
(Ken)
June 27, 2011, 3:27pm
5
No, I have used a workaround… str_pad().
If anyone knows what is missing please let me know.
My order_no column is set to INT(10) unsigned zerofill.
When I add a new record, the zerofill works.
When I pull that information using the table model it works.
But right after the save, if I print the value of the order_no, it shows without zerofill.
You could try $model->refresh() to make Yii requery the data in the model. That should solve it, but does use an extra query.
This behavior could probably be added to Yii btw, have you filed a bug for this?
kheang
(Ken)
June 28, 2011, 11:40am
7
Thanks I will try that and see if it works!
No I haven’t filed a bug… i’m kind of new at this.
kheang
(Ken)
June 28, 2011, 12:08pm
8
It works with refresh, thanks!
I will submit a bug.
kheang
(Ken)
June 29, 2011, 12:44am
9
Just an update, I got this reply:
Comment 1 by project member qiang.xue, Today (6 minutes ago):
We can’t solve this problem. The value 1, 2 are returned by the last inerstID call from PDO. In this rare case, you will have to call refresh() as you described to work around the issue.
mdomba
(Maurizio Domba Cerin)
June 29, 2011, 7:29am
10
If you have time… you can check this with pure PHP (no Yii)… so if PDO is the one returning 1,2 instead of "00001","00002"… this can be a bug of the PDO driver… and you can report it to PHP
kheang
(Ken)
June 29, 2011, 10:19am
11
I am not sure how to check that
mdomba
(Maurizio Domba Cerin)
June 29, 2011, 10:30am
12