如何在插入表(codeigniter)之前从数组中替换字符串?

时间:2016-09-08 06:08:37

标签: php mysql codeigniter

将数据插入数据库时​​遇到问题。 我得到这样的错误

    <!DOCTYPE HTML>
    <html>
    <head>
    <script type='text/javascript' src='//code.jquery.com/jquery-2.2.3.js'></script>
    <script type="text/javascript" src="https://raw.github.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script>
    </head>
    <body>
    <div id='anteprima' ></div>
    <div id='anteprima_img' ></div>

    <script type="text/javascript">
    var file = 'http://www.businessmodelgeneration.com/downloads/businessmodelgeneration_preview.pdf';
    pdftoimg(file, 1, 0.5, 'anteprima');

    function pdftoimg(file, num, scale2, idd) {
        PDFJS.disableWorker = true;
        PDFJS.getDocument(file).then(function(pdf) {
            pdf.getPage(num).then(function(page) {
                var canvas = document.createElement('canvas');
                canvas.id = 'pag' + num;
                canvas.className = 'grande';
                canvasContainer = document.getElementById(idd);
                var context = canvas.getContext('2d');
                var viewport = page.getViewport(scale2);
                canvas.height = viewport.height;
                canvas.width = viewport.width;
                var renderContext = {
                    canvasContext: context,
                    viewport: viewport
                };
                page.render(renderContext).then(function(){
                    canvasContainer.appendChild(canvas);
                    var dataUrl = canvas.toDataURL();
                    image = document.createElement('img');
                    image.src = dataUrl;
                    $('#anteprima_img').html(image);
                });
            });
        });
    };

    </script>
    </body>
    </html>

如何从

中替换sql查询中的列名
class CDR_NOR(SUBSCRIBER_ID:String, CHARGING_ID:String, NODE_ID:String, val START_TIME:String) extends Ordered [CDR_NOR]
 {
    def compare(that: CDR_NOR) = {
if (this.START_TIME.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}[\\s]{1}[\\d]{2}:[\\d]{2}:[\\d]{2}:[\\d]+") && that.START_TIME.matches("[\\d]{4}-[\\d]{2}-[\\d]{2}[\\s]{1}[\\d]{2}:[\\d]{2}:[\\d]{2}:[\\d]+")) {
    val formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss:SSS")
    val d1 = formatter.parseDateTime(this.START_TIME)
    val d2 = formatter.parseDateTime(that.START_TIME)
    d1.compareTo(d2)
  }
  else
  0
 }
}

 case class DXE_NOR(SUBSCRIBER_ID:String, CHARGING_ID:String, NODE_ID:String,
               START_TIME:String, DXE_PROTOCOL_ID:String, DXE_SUB_PROTOCOL_ID:String, DXE_APPLICATION_ID:String, DXE_INTERNET_SERVER_IP:String,
               DXE_SENDER_ID: String, DXE_USAGE_TYPE: String, DXE_FILE_Population_TIME: String, DXE_IMSI: String, DXE_MSISDN: String, DXE_IMEI: String, DXE_CHARGING1_ID: String, DXE_UE_IP_ADDRESS: String,
               DXE_SESSION_ID: String, DXE_BEARER_CREATION_TIME: String, DXE_EVENT_START_TIME: String, DXE_EVENT_END_TIME: String, DXE_DURATION: String, DXE_UPLINK_VOL: String, DXE_DOWNLINK_VOL: String, DXE_TOTAL_VOL: String, DXE_RAT_TYPE: String,
               DXE_CELL_ID: String, DXE_ECELL_ID: String, DXE_HPMN: String, DXE_VPMN: String, DXE_SUBSCRIBER_TYPE: String, DXE_ROAM_TYPE: String, DXE_HANDSET_CATEGORY: String, DXE_GATEWAY_IP_ADDRESS: String,
               DXE_SERVING_IP_ADDRESS: String, DXE_APN: String, DXE_APN_TYPE: String, DXE_APP_NAME: String, DXE_DOMAIN_NAME: String,
               DXE_HTTP_PROXY_SERVER_IP_ADDRESS: String, DXE_PROXY_DOMAIN_NAME: String, DXE_CHARGING_CHARACTERISTICS: String, DXE_APN_RA_FLAG: String, DXE_APP_RA_FLAG: String, DXE_URL_RA_FLAG: String, DXE_Original_FILE_NAME: String
              ) extends CDR_NOR(SUBSCRIBER_ID,CHARGING_ID,NODE_ID,START_TIME)

Unknown column 'p.id_sp' in 'field list' 。在运行插入函数之前?

这里是数组示例

`p`.`id_sp'`

这里我插入代码

'p.id_sp'

2 个答案:

答案 0 :(得分:0)

从列名中删除',我不知道是否可行。 但是你可以做的是创建那些有问题的列的别名进入某个临时表。然后运行你的数组并插入命令。

答案 1 :(得分:0)

CI为了使这个查询安全而在查询中添加Backticks和类似的东西,但是在你的情况下看起来似乎不能让CI完成所有工作,因为你使用带点的列名

尝试按如下方式更改代码:

foreach($data["result"] as $key){
    $insert=$this->db->insert($database, $key, false);
}

但请记住,您现在必须手动转义数据

有关详细信息,请查看query builder docsdriver reference docs