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;


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?

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?

I am using it to display an order number.

So you set id_customer columns as INT(8) and you expect to get 00000001 instead of 1 ? Interesting, I haven’t thought about this. Btw, Have you solved your issue ? Please share

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?

Thanks I will try that and see if it works!

No I haven’t filed a bug… i’m kind of new at this.

It works with refresh, thanks!

I will submit a bug.

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.

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

I am not sure how to check that :(

Here is a nice tutorial -