我通过类型转换,通过intval()和其他程序转换,但从 $ Id(字符串:例如“99973132”)返回的内容总是 0 。如果有人能指导我,我将不胜感激。我从字符串转换为int的值是长度 99973132(所有值都接近于此值)。我已经越过了检查。 $ Id 中返回的值为 99973132 ,但转换结果为 0
<?php
require_once('../SchemaBuilder/Dbconfig.php');
require_once('../SchemaBuilder/NativeConfiguration.php');
$servername = MYSERVERNAME;
$username = MYUSERNAME;
$password = MYPW;
$dbname = MYDBNAME;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(!file_exists($_FILES['csvdata']['tmp_name']) || !is_uploaded_file($_FILES['csvdata']['tmp_name']))
{ echo "no file";
echo "<br> No file Selected press back to try again!!<br>";
}
else
{
$content= file_get_contents($_FILES["csvdata"]["tmp_name"]);
$content= file_get_contents($_FILES["csvdata"]["tmp_name"]);
$lines = explode("\n", $content);
$i = 0;//initialize
foreach($lines as $value)
{
if($i != 0)
{
$cols[$i] = explode("\t", $value);
if(isset($cols[$i][9]))
{ $id=$cols[$i][0] +0;
$query = "INSERT INTO csvdata(Id,UserName)
VALUES(".$i.", '".$cols[$i][9]. "')" ;
if ($conn->query($query) === TRUE)
{
echo "New record created successfully".'<br>';
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error.'<br>';
}
$x++;
}
}
$i++;
}
$conn->close();
}
?>
编辑我正在加载.tsv文件,之后通过滑动第一行解析每一行,然后按 \ t 进行爆炸。获取 $ id 中的第一个属性并将其转换为整数。但它未转换并给出0