dsa1234569 2013-07-01 14:42
浏览 53

PHP内爆不使用单引号?

I've searched for about the last hour regarding this issue, but its becoming quite annoying...

Anyways, I'm trying to insert data into a mysqli db, i've done this numerous times before but for some reason I cannot figure out what is going wrong...

<?php

require_once("../config/dbmetar.php");

$delimiter = ',';
$file = "metars.csv";
$db = new mysqli(DB_HOST_METAR, DB_USER_METAR, DB_PASS_METAR, DB_NAME_METAR);
$r = 0;

if (($handle = fopen($file, "r")) !== FALSE) {

while (($data = fgetcsv($handle, 5000, $delimiter)) !== FALSE) {

    if ($r >= 6) {

        foreach($data as $i => $content) { 

            $data[$i] = $db->real_escape_string($content);

        }

        echo "INSERT INTO metars VALUES('" . implode("','", $data) . "');" . "<br>";
        //$db->query("INSERT INTO metars VALUES('" . implode("','", $data) . "');" );

    }

    $r++;

}

fclose($handle);
}

?>

The main issue is with the insert into metars values... the values should all be comma delimited with single quotes around each field value...

Currently this is what the echo is exporting:

INSERT INTO metars VALUES('PAJZ 011132Z AUTO 1 3/4SM BR FEW009 BKN019 OVC026 08/07 A2959 RMK AO2 PWINO TSNO P0001,PAJZ,2013-07-01T11:32:00Z,59.73,-157.27,8.0,7.0,,,,1.75,29.589567,,,TRUE,TRUE,,,TRUE,,TRUE,BR,FEW,900,BKN,1900,OVC,2600,,,IFR,,,,,,0.01,,,,,,SPECI,82.0');

Any suggestions?

Var_dump($data) returned these:

array(1) { [0]=> string(238) "PAJZ 011132Z AUTO 1 3/4SM BR FEW009 BKN019 OVC026 08/07 A2959 RMK AO2 PWINO TSNO P0001,PAJZ,2013-07-01T11:32:00Z,59.73,-157.27,8.0,7.0,,,,1.75,29.589567,,,TRUE,TRUE,,,TRUE,,TRUE,BR,FEW,900,BKN,1900,OVC,2600,,,IFR,,,,,,0.01,,,,,,SPECI,82.0" } INSERT INTO metars VALUES('');
array(1) { [0]=> string(153) "CYOD 011131Z 18002KT 1/2SM FG FEW250 RMK CI0,CYOD,2013-07-01T11:31:00Z,54.4,-110.28,,,180,2,,0.5,,,,,,,,,,,FG,FEW,25000,,,,,,,LIFR,,,,,,,,,,,,SPECI,544.0" } INSERT INTO metars VALUES('');
array(1) { [0]=> string(276) "CYYD 011131Z AUTO VRB06KT 5SM -RA BR FEW007 BKN070 OVC084 15/14 A3005 RMK PRESRR PCPN 1.0MM PAST HR SLP173 DENSITY ALT 1900FT,CYYD,2013-07-01T11:31:00Z,54.82,-127.18,15.0,14.0,0,6,,5.0,30.050198,1017.3,,TRUE,,,,,,,-RA BR,FEW,700,BKN,7000,OVC,8400,,,MVFR,,,,,,,,,,,,SPECI,523.0" } 
  • 写回答

2条回答 默认 最新

  • dounue1965 2013-07-01 14:46
    关注

    This means $data has 1 item, because implode works just fine this way.

    var_dump($data);
    

    Please run the dump. Maybe you have wrong delimiter, so $data has one single element.

    评论

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP