[状态:学习者]
我总是使用mysql,但这次我想学习一些新东西(准备好的陈述)。我在另一个问题中找到了这个代码,但是我看到了类似的代码,我发现,我无法想象第3行中的“sss”意味着什么。
$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();
这是第二行中具有相同问题的另一个代码:'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>";
请你帮我解释一下吗?
答案 0 :(得分:4)
它是一个规范字符,表示它可以预期的数据类型。在你的情况下,它是3个字符串变量。
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