duanjue2560 2014-03-21 14:43
浏览 25
已采纳

预准备语句的绑定参数中的第一个参数(?)/ value(?)是什么?

[ Status: Learner ]

I always use mysql, but this time i wanted to learn something new(prepared statements). I found this code in an other question, but I saw similar codes to this, and I found, that I can't imagine what is the "sss" in the 3rd row means.

$query = "INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)";
$stmt = $mysqli->prepare($query);

$stmt->bind_param("sss", $val1, $val2, $val3);

$val1 = 'Stuttgart';
$val2 = 'DEU';
$val3 = 'Baden-Wuerttemberg';

/* Execute the statement */
$stmt->execute();

Here's another code with the same problem in the 2nd row: 'dd'

$stmt = $conn->prepare ( 'SELECT author, title FROM books where price < ? and weight > ?' );

$stmt->bind_param('dd',$price,$weight);

$price=15.; //RON
$weight=300.; //g 

if (!$stmt->execute()) die ("Unsuccessfull query.");

$stmt->bind_result($author, $title);
echo "Big weight (>$weight g) and cheap books (< $price RON) <br>";

Could you explain it please for me please?

  • 写回答

1条回答 默认 最新

  • dtdd25012 2014-03-21 14:45
    关注

    It's a specification character indicating what type of data type it can expect. In your case, it's 3 string variables.

    Char    Description
    i       corresponding variable has type integer
    d       corresponding variable has type double
    s       corresponding variable has type string
    b       corresponding variable is a blob and will be sent in packets
    

    See the documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源