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

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

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line