php—如何从输入框中获取存储过程的参数

w51jfk4q  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(320)

在这里,我调用了运行良好的存储过程,但是我想给出输入框中的参数,如何从输入框中获取参数

<?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";
        }
?>
vqlkdk9b

vqlkdk9b1#

这里有一个可能的解决方案:

<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";
  }
}

相关问题