catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

$database->id() return ZEROFILL id value. #1015

Closed MmToon closed 2 years ago

MmToon commented 2 years ago

Information

Describe the Problem 数据表id设置了自增且零填充,查询的时候没问题 比如查询后的结果是 ['id' => '000001', 'name' => 'MmToon'] 但插入数据后获取自增id却不带零填充,这属于正常吗? 获取自增id是字符串类型的,所以不会存在整型忽略

Detail Code $database->insert('user', [ 'name' => 'MmToon', ]); $user_id = $database->id(); var_dump($user_id);

输出 string(1) "1"

Expected output 预期 string(1) "00001"

------- Translated by Google --------

Information -Version of Medoo: Version 1.7.10 -Type of Database: MySQL5.6.44 -System: CentOS 7.3.1611 x86_64

Describe the Problem The data table id is set with auto-increment and zero-filling, and there is no problem when querying For example, the result of the query is

['id' => '000001','name' =>'MmToon']

But after inserting the data, it is normal to get the auto-increment id without zero-padding? Obtaining self-increasing id is of string type, so there will be no integer ignore

Detail Code

$database->insert('user', [
         'name' =>'MmToon',
]);
$user_id = $database->id();
var_dump($user_id);

Output string(1) "1"

Expected output expected string(1) "00001"

catfan commented 2 years ago

This problem is discussed and has a detailed answer by David Gebler https://externals.io/message/113294.