如何从输入框中获取存储过程的参数
How to get the stored procedure's parameter from an input box
这里我调用了存储过程,它工作正常,但我想在输入框中给出参数,如何从输入框中获取该参数
<?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
$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";
}
}