-2

我正在尝试将一些数据从 CSV 文件(带有标题)导入 MySQL 表。我已经调试了这个脚本,它似乎一直在工作,直到“句柄”变量。当我运行此代码时,我得到一个空白屏幕,并且 MySQL 表未使用 CSV 数据更新。我可能在这里遗漏了一些东西。任何帮助表示赞赏!

谢谢,

AME

这是代码:

<?PHP

error_reporting(E_ALL & ~E_NOTICE);
if (ini_get('display_errors') === FALSE) {
ini_set('display_errors', 1);
}

$dbhost = 'localhost';
$dbuser = 'myusernam';
$dbpasswd = 'mypassword';
$db = "dbname";

$dbh = mysql_connect($dbhost, $dbuser, $dbpasswd) or die("Unable to connect to SQL server");
$my_db = @mysql_select_db($db, $dbh) or die("Unable to select database");

$file = $_SERVER['DOCUMENT_ROOT']."/home/test.csv";

$handle = fopen($file, "r");

while (($fileop = fgetcsv($handle,1000,",")) !==false)
{

    $listid = $fileop[0];
    $listclass = $fileop[1];
    $type = $fileop[2];
    $status = $fileop[3];
    $remarks = $fileop[3];
    $streetaddress = $fileop[6];
    $fulladdress = $fileop[6].",".$fileop[7].",".$fileop[8];
    $orgname = $fileop[9];
    $licenseid = $fileop[10];
    $agentname = $fileop[12]." ".$fileop[12];
    $imagecount = $fileop[13];

    $sql = mysql_query("INSERT INTO markers (id,Class,Status,AskingPrice,Remarks,StreetAddres,address,OrgName,AgentLicenseID,AgentName,ImageCount) VALUES ('$listid','$listclass','$type','$status','$remarks','$streetaddress','$fulladdress','$orgname','$licenseid','$agentname','$imagecount')");

}

    if($sql)
    {
        echo 'data uploaded successfully';
    }

?>
4

1 回答 1

2

Sounds to me like your file permissions are not correct, so your unable to read the file! To get error messages to output to your browser add this just under your <?php tag:

error_reporting(E_ALL & ~E_NOTICE);
if (ini_get('display_errors') === FALSE) {
    ini_set('display_errors', 1);
}

If it's not the file permissions at least it should hopefully output something more useful to us!

于 2012-12-16T09:11:52.550 回答