• <small id='Kg7Wx'></small><noframes id='Kg7Wx'>

      <bdo id='Kg7Wx'></bdo><ul id='Kg7Wx'></ul>

      <i id='Kg7Wx'><tr id='Kg7Wx'><dt id='Kg7Wx'><q id='Kg7Wx'><span id='Kg7Wx'><b id='Kg7Wx'><form id='Kg7Wx'><ins id='Kg7Wx'></ins><ul id='Kg7Wx'></ul><sub id='Kg7Wx'></sub></form><legend id='Kg7Wx'></legend><bdo id='Kg7Wx'><pre id='Kg7Wx'><center id='Kg7Wx'></center></pre></bdo></b><th id='Kg7Wx'></th></span></q></dt></tr></i><div id='Kg7Wx'><tfoot id='Kg7Wx'></tfoot><dl id='Kg7Wx'><fieldset id='Kg7Wx'></fieldset></dl></div>

      <legend id='Kg7Wx'><style id='Kg7Wx'><dir id='Kg7Wx'><q id='Kg7Wx'></q></dir></style></legend>
    1. <tfoot id='Kg7Wx'></tfoot>
      1. PHP 将旧的 mysql_query 更改为 PDO

        时间:2023-09-20
        <i id='Ccb39'><tr id='Ccb39'><dt id='Ccb39'><q id='Ccb39'><span id='Ccb39'><b id='Ccb39'><form id='Ccb39'><ins id='Ccb39'></ins><ul id='Ccb39'></ul><sub id='Ccb39'></sub></form><legend id='Ccb39'></legend><bdo id='Ccb39'><pre id='Ccb39'><center id='Ccb39'></center></pre></bdo></b><th id='Ccb39'></th></span></q></dt></tr></i><div id='Ccb39'><tfoot id='Ccb39'></tfoot><dl id='Ccb39'><fieldset id='Ccb39'></fieldset></dl></div>
        <legend id='Ccb39'><style id='Ccb39'><dir id='Ccb39'><q id='Ccb39'></q></dir></style></legend>

              <bdo id='Ccb39'></bdo><ul id='Ccb39'></ul>
                <tbody id='Ccb39'></tbody>

              <small id='Ccb39'></small><noframes id='Ccb39'>

                • <tfoot id='Ccb39'></tfoot>
                • 本文介绍了PHP 将旧的 mysql_query 更改为 PDO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的代码中有一些旧的 mysql_query 查询,我想将其转换为 PDO,但正在努力工作.

                  I have some old mysql_query queries in my code which i want to convert in to PDO but am struggling to get to work.

                  我的原始代码是:

                  mysql_query("UPDATE people SET price='$price', contact='$contact', fname='$fname', lname='$lname' WHERE id='$id' AND username='$username' ")
                  or die(mysql_error()); 
                  

                  现在我正在尝试:

                  $sql = "UPDATE people SET price='$price', contact='$contact', fname='$fname', lname='$lname' WHERE id='$id' AND username='$username'";
                  $q   = $conn->query($sql) or die("failed!");
                  

                  但似乎无法让它工作,有什么想法吗?

                  but can't seem to get it to work, any ideas?

                  更新代码:

                  $conn = new PDO("mysql:host=$host;dbname=$db",$user,$pass);
                  
                  
                   // check if the form has been submitted. If it has, process the form and save it to the   database
                   if (isset($_POST['submit']))
                   { 
                   // confirm that the 'id' value is a valid integer before getting the form data
                   if (is_numeric($_POST['id']))
                    {
                   // get form data, making sure it is valid
                   $id = $_POST['id'];
                   $fname = mysql_real_escape_string(htmlspecialchars($_POST['fname']));
                   $lname = mysql_real_escape_string(htmlspecialchars($_POST['lname']));
                   $contact = mysql_real_escape_string(htmlspecialchars($_POST['contact']));
                   $price = mysql_real_escape_string(htmlspecialchars($_POST['price']));
                  
                  
                   // check that firstname/lastname fields are both filled in
                   if ($fname == '' || $lname == '' || $contact == '' || $price == '' )
                   {
                   // generate error message
                   $error = 'ERROR: Please fill in all required fields!';
                  
                   //error, display form
                   renderForm($id, $fname, $lname, $contact, $price, $error);
                   }
                   else
                   {
                   // save the data to the database
                   $username = $_SESSION['username'];
                  
                   $query = "UPDATE people 
                           SET price=?, 
                               contact=?, 
                               fname=?, 
                               lname=? 
                            WHERE id=? AND 
                                  username=?";
                  $stmt = $db->prepare($query);
                  $stmt->bindParam(1, $price);
                  $stmt->bindParam(2, $contact);
                  $stmt->bindParam(3, $fname);
                  $stmt->bindParam(4, $lname);
                  $stmt->bindParam(5, $id);
                  $stmt->bindParam(6, $username);    
                  $stmt->execute();
                  
                  
                   // once saved, redirect back to the view page
                  header("Location: view.php"); 
                  }
                  

                  推荐答案

                  有关更多信息,请访问此链接:PHP PDO

                  For more information visit this link: PHP PDO

                  根据您的示例,

                  <?php
                  
                      $query = "UPDATE people 
                               SET price=?, 
                                   contact=?, 
                                   fname=?, 
                                   lname=? 
                                WHERE id=? AND 
                                      username=?";
                      $stmt = $dbh->prepare($query);
                      $stmt->bindParam(1, $price);
                      $stmt->bindParam(2, $contact);
                      $stmt->bindParam(3, $fname);
                      $stmt->bindParam(4, $lname);
                      $stmt->bindParam(5, $id);
                      $stmt->bindParam(6, $username);    
                      $stmt->execute();
                  
                  ?>
                  

                  PDO 准备好的语句和存储过程

                  这篇关于PHP 将旧的 mysql_query 更改为 PDO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PDO 上 bind_result 的等价物是什么 下一篇:编辑 NetBeans 源格式标准

                  相关文章

                  最新文章

                  <i id='iHaC7'><tr id='iHaC7'><dt id='iHaC7'><q id='iHaC7'><span id='iHaC7'><b id='iHaC7'><form id='iHaC7'><ins id='iHaC7'></ins><ul id='iHaC7'></ul><sub id='iHaC7'></sub></form><legend id='iHaC7'></legend><bdo id='iHaC7'><pre id='iHaC7'><center id='iHaC7'></center></pre></bdo></b><th id='iHaC7'></th></span></q></dt></tr></i><div id='iHaC7'><tfoot id='iHaC7'></tfoot><dl id='iHaC7'><fieldset id='iHaC7'></fieldset></dl></div>

                      <tfoot id='iHaC7'></tfoot>
                        <bdo id='iHaC7'></bdo><ul id='iHaC7'></ul>

                      <legend id='iHaC7'><style id='iHaC7'><dir id='iHaC7'><q id='iHaC7'></q></dir></style></legend>
                    1. <small id='iHaC7'></small><noframes id='iHaC7'>