gpt4 book ai didi

PHP:如何在插入语句中包含第一个数字零

转载 作者:行者123 更新时间:2023-11-29 01:12:59 26 4
gpt4 key购买 nike

我正在尝试插入第一个数字为零的数字

当我尝试添加前缀000012345

只会增加12345

当我尝试添加前缀012345

只会增加12345

我的数据类型是 INT(11)

 $sql = "INSERT INTO circle_call_prefixes (circle, prefix)
VALUES (?,?)";
$stmt = $dbh->prepare($sql);
$stmt ->execute(array($destination , $prefix ));
$Last_ID = $dbh->lastInsertId();
$sql_table2 = "INSERT INTO circle_call_destinations
(autoNo,destination, source_circle, comment) VALUES (?,?,?,?)";
$stmt = $dbh->prepare($sql_table2);
$stmt -> execute(array($Last_ID, $destination, $source_circle, $comment));

谢谢

最佳答案

在 MySql 中,你可以填充字段,如果你知道最终长度,因为你的列的长度是 11,如果你需要在左边填充 0 直到你的列的长度,那么你可以使用 LPAD 函数,如:

SELECT LPAD(12345, 11, '0') FROM tableName;

关于PHP:如何在插入语句中包含第一个数字零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36077909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com