首先我正在创建调用存储过程的函数,所以我想用pdo做同样的事情我已经尝试了不同的方法搜索了很多但是找不到合适的解决方案 我的function.php
<?php
function AddWords($word,$meaning,$synonym,$antonym){
include("conn.php");
$result=mysqli_query($conn,"CALL AddWords('$word','$meaning','$synonym','$antonym')");
//echo "CALL AddWords('$word','$meaning','$synonym','$antonym')";
return $result;
}
function GetWords($word){
include("conn.php");
$result=mysqli_query($conn,"CALL GetWords('$word')");
return $result;
}
function GetAdminWords(){
include("conn.php");
$result=mysqli_query($conn,"CALL GetAdminWords()");
return $result;
}
function GetWordsByID($id){
include("conn.php");
$result=mysqli_query($conn,"CALL GetWordsById($id)");
return $result;
}
function Deletewords($id){
include("conn.php");
$result=mysqli_query($conn,"CAll DeleteWords($id)");
return $result;
}
function UpdateWords($word,$meaning,$synonym,$antonym,$id){
include("conn.php");
$result=mysqli_query($conn,"CALL UpdateWords('$word','$meaning','$synonym','$antonym',$id)");
//echo "CALL UpdateWords('$word','$meaning','$synonym','$antonym',$id)";
return $result;
}
function SortContent(){
include("conn.php");
$result=mysqli_query($conn,"CALL SortContent()");
return $result;
}
function SortContent2(){
include("conn.php");
$result=mysqli_query($conn,"CALL SortContent2()");
return $result;
}
?>
然后在我正在使用mysqli_escape_string的主文件中调用此函数 我想在pdo实现 我的主文件
<?php
include("conn.php");
include("function.php");
if(isset($_POST['btn_submit'])){
$word=$_POST['word'];
$meaning=$_POST['meaning'];
$antonym=$_POST['antonym'];
$synonym=$_POST['synonym'];
if(!isset($_GET['id1'])){
$result=AddWords(mysqli_escape_string($conn,$word),mysqli_escape_string($conn,$meaning),mysqli_escape_string($conn,$synonym),mysqli_escape_string($conn,$antonym));
echo "<script type='text/javascript'>alert('Saved Successfully!!')</script>";
echo "<script type='text/javascript'>window.location='view.php'</script>";
}
if(isset($_GET['id1'])){
//echo $_GET['id1'];
$id=$_GET['id1'];
$result=UpdateWords(mysqli_escape_string($conn,$word),mysqli_escape_string($conn,$meaning),mysqli_escape_string($conn,$synonym),mysqli_escape_string($conn,$antonym),$id,$conn);
echo "<script type='text/javascript'>alert('Saved Successfully!!')</script>";
echo "<script type='text/javascript'>window.location='view.php'</script>";
}
}
?>
在我的代码中我主要使用mysqli_escape_string
<?php
if(isset($_GET['id1'])){
$id=$_GET['id1'];
$result=GetWordsById(mysqli_escape_string($conn,$id));
if(mysqli_num_rows($result)>0)
$row=mysqli_fetch_array($result);
$word=$row['word'];
$meaning=$row['meaning'];
$synonym=$row['synonym'];
$antonym=$row['antonym'];
}
?>
<form method="post">
<div class="container container-fluid">
<div class="form-group">
<div class="col-xs-4">
<label for="inputdefault">Add Word</label>
<input class="form-control" id="inputdefault" type="text" name="word" value="<?php if(isset($word)){echo $word;}?>">
<label for="inputdefault">Add Meaning</label>
<input class="form-control" id="inputdefault" type="text" name="meaning" value="<?php if(isset($meaning)){echo $meaning;}?>">
<label for="inputdefault">Add Synonym</label>
<input class="form-control" id="inputdefault" type="text" name="synonym" value="<?php if(isset($synonym)){echo $synonym;}?>">
<label for="inputdefault">Add Antonym</label>
<input class="form-control" id="inputdefault" type="text" name="antonym" value="<?php if(isset($antonym)){echo $antonym;}?>"><br>
<button type="submit" class="btn btn-primary" name="btn_submit" >Submit</button>