将CSV数据导入PHP中的MySAQL数据库并显示错误


import csv data to mysaql database in php and show error

我想在php中将csv数据文件导入masql databse。

我想知道哪一行和哪一列的数据格式有错误

像第 24 行和列电话号:数据不是数字。

请帮帮我

例如,我做了这个函数

function phoneValidate($phone)
{
    global $err;
    if(ctype_digit($phone) && strlen((string)$phone) == 10)
    {
        return 1;
    }
    else
    {
        array_push($err , "phone");
        return 0;
    }
}

我在验证中使用它

while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
    if(phoneValidate())

要指定错误的位置,您可以使用计数器进行模拟游戏:

$i = 1;
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE){
    for ( $x = 0; $x < count ( $emapData ); $x++ )
    {
         if(!validate($emapData[$x])){ //example, $x would be the column
             echo 'Error in line ' . $i . ' on column ' . $x;
         }
    }
    $i++; //row
}

我希望我做对了...