这里我调用了工作正常的存储过程,但我想在输入框中给出参数,如何从输入框中获取该参数
<?php
$con = new PDO("mysql:host=localhost;dbname=acc_project_inv",'root','');
$sql = "CALL calcPro('2018-03-31')";
$result = $con->prepare($sql);
$result->setFetchMode(PDO::FETCH_ASSOC);
$result->execute();
if ($result) {
echo "Calculated";
}else{
echo "Report Development Team";
}
?>
最佳答案
这是一种可能的解决方案:
<html>
<body>
<form method="post">
<input type="text" name="yymmdd">
<input type="submit" value="Do it!">
</form>
</body>
</html>
<?php
$con = new PDO("mysql:host=localhost;dbname=acc_project_inv",'root','');
if (!empty($_POST["yymmdd"])) {
$ymd = $_POST["yymmdd"];
// You should add more checks here to make sure that the $ymd
// variable only contains expected characters (since it's user
// input)
$sql = "CALL calcPro( :yyyymmdd )";
$result = $con->prepare($sql);
$result->setFetchMode(PDO::FETCH_ASSOC);
$result->execute([":yyyymmdd" => $ymd]);
if ($result) {
echo "Calculated";
} else {
echo "Report Development Team";
}
}
关于php - 如何从输入框中获取存储过程的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53259350/