dtj4307 2016-12-10 16:06
浏览 43
已采纳

concat php值与sql查询中的整个引号

How to concat this php value with entire quotes in sql query, so that it saves as properly in phpmyadmin database?

 $db = new mysqli('localhost','root','','geo'); 

// Each value is a placeholder

$sql = "UPDATE file_contents SET Origin_URL = CONCAT('https://www.google.com/maps/dir/', ?, ',' ?, '/', ?, ',', ?) WHERE Sl = 1 LIMIT 6";

$stmt = $db ->prepare($sql);

// First parameter should correspond to number and types of your arguments
// You have 5, first four are strings, fifth is a number, so "ssssd"

$stmt->bind_param($OriginLatId,$OriginLongId,$DestinationLatId,$DestinationLongId);

$stmt->execute();

Please help me get the correct sql query to insert this url in my database successfully, this is the table, and I have made the Origin_URL column into a varchar column. The data goes into this column.

This is table, and I have made the Origin_URL column into a varchar column. The data goes into this column.

  • 写回答

3条回答 默认 最新

  • duandaiqin6080 2016-12-10 17:05
    关注

    There are a number of issues with your string concatenation, + is for addition, variables in single quotes are strings, not variables, and you seem to be adding quotes in too many instances.

    You should be able to build your string with the complex curly braces in double quotes:

    $val1 = "https://www.google.com/maps/dir/{$OriginLatId},{$OriginLongId}/{$DestinationLatId},{$DestinationLongId}";
    

    You can read more about this here, http://php.net/manual/en/language.types.string.php.

    or by standard concatenation:

    $val1 = 'https://www.google.com/maps/dir/' .  $OriginLatId .',' . $OriginLongId . '/' . $DestinationLatId . ',' . $DestinationLongId;
    

    You can read more about this here, http://php.net/manual/en/language.operators.string.php.

    Then just write that to the DB. There's no need for the mysql concat function.

    $sql = 'UPDATE file_contents 
    SET Origin_URL = ? 
    WHERE Sl = 1 LIMIT 6';
    $stmt = $db->prepare($sql);
    $stmt->bind_param('s', $val1);
    $stmt->execute();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类