如何在数据库中存储字符串(其(整数值)大于整数,在php中),其中列的类型为BIGINT

时间:2015-11-10 13:36:24

标签: php mysql mysqli

我有一个整数字符串,其长度(整数值)大于
    32位PHP中整数的大小。

我想将这个整数字符串存储到我拥有的mysql数据库中 列中的BIGINT。所以请建议任何方法来解决这个问题。

example. 
$string = "70548752155";
and I have to store that number into a table where column is of type BIGINT

I am using mysqli to work with mysql database.

我正在使用此代码插入数据库。

<?php
session_start();
include 'mysqlConnection.php';
$first_name = $_SESSION["firstName"];
$last_name = $_SESSION["lastName"];;
$mobile_number = $_SESSION["mobileNumber"];
$email =  $_SESSION["email"];
$cryptedpwd = $_SESSION["pwd"];
$query = "INSERT INTO customer (firstName, lastName, mobileNumber, email, pwd) VALUES " .
"('{$first_name}', '{$last_name}',  '{$mobile_number}', '{$email}', '{$cryptedpwd}'); ";
$result = mysqli_query($conn, $query);
if(!$result){
    die ("Database query failed.");
}
else{
    echo "Query Sucessfull.";
}

&GT;

1 个答案:

答案 0 :(得分:1)

您不必更改字符串的数据类型。 MySQL将根据其值自动调整列中的值。只要您的字符串仅包含数字符号,您的查询就会运行。

$bigInt = '70548752155';

if ($mysqli->query('INSERT INTO `table` (`column`) VALUES ("'.$bigInt.'")')) {
    echo 'Row successfully inserted.';
}