简体   繁体   中英

How to handle BIGINT on PHP Laravel

I've got a project that create a web page using PHP Laravel, and want to create a user login. On the database I created UserID column, with varchar as the data type, the User ID format 'USxxxxxxxxxx' the x are number and it will auto increment. So I create a function to substring the number and change it to Int so it will auto increment when new user register to the web. After the increment, the number will store back to a string.

My question is is PHP Laravel can handle 10 digits number(Billion) and what data type that should I use on PHP Laravel?

You shouldn't use VARCHAR for BIGINT. Use bigIncrements() in Laravel migrations for increment:

$table->bigIncrements('id');

And bigInteger() for BIGINT:

$table->bigInteger('votes');

https://laravel.com/docs/5.4/migrations#columns

Core PHP Logic you should be implement as Laravel syntax

$qry = mysql_query("SELECT * FROM `user` ORDER by `UserID` DESC LIMIT 1");
$row = mysql_fetch_array($qry);

$last_id = $row['UserID'];
$userid = substr($string, 2);
$userid = $userid + 1;
$userid = 'US'.$userid;

// Now you can Insert

$insert_qry = mysql_query("INSERT INTO `user` (`UserID`) VALUES ('".$userid."')");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM