<legend id='wYhW6'><style id='wYhW6'><dir id='wYhW6'><q id='wYhW6'></q></dir></style></legend>
  • <tfoot id='wYhW6'></tfoot>

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

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

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

        如何使用pdo从sql中删除数据?

        时间:2023-09-20

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

                • <legend id='xm2aV'><style id='xm2aV'><dir id='xm2aV'><q id='xm2aV'></q></dir></style></legend>

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

                • <tfoot id='xm2aV'></tfoot>
                  本文介绍了如何使用pdo从sql中删除数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  您好,我整天都在网上搜索,试图找到使用 pdo 时删除数据的示例,但我只找到了它的 MySQL 和 MySQLi,我卡住了,我运行它时看不到我遗漏了什么,它给了我/search.php?del=Array(id).这是我的代码,请帮忙

                  Hello I have search the web all day trying to find example of deleting data when I use pdo but all i found its MySQL and MySQLi and I am stuck i can't see what I am missing when I run it it give me /search.php?del=Array(id). This its my code please help

                  <?php 
                  //load database connection
                      $host = "localhost";
                      $user = "abcd";
                      $password = "******";
                      $database_name = "abcd";
                      $pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
                      PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
                      ));
                  // Search from MySQL database table
                  
                  
                  
                  
                  $search=$_POST['search'];
                  $query = $pdo->prepare("select * from wfuk where post_code LIKE '%$search%' OR telephone LIKE '%$search%'  LIMIT 0 , 10");
                  $query->bindValue(1, "%$search%", PDO::PARAM_STR);
                  $query->execute();
                  // Display search result
                  ?>
                  <html>
                  <head>
                  <title> How To Create A Database Search With MySQL & PHP Script | Tutorial.World.Edu </title>
                  </head>
                  <body>
                  <form action="search.php" method="post">
                  Search: <input type="text" name="search" placeholder=" Search here ... "/>
                  <input type="submit" value="Submit" />
                  </form>
                  <?php
                           if (!$query->rowCount() == 0) {
                  		 		echo "Search found :<br/>";
                  				echo "<table style="font-family:arial;color:#333333;">";	
                                  echo "<tr>
                  				<td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">First Name</td>
                  				<td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Last Name</td>
                  				<td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Trade</td>
                  				<td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Post Code</td>
                  				<td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Telephone</td>
                  				<td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Comments</td>
                  				<td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">To be use</td></tr>";			
                              while ($results = $query->fetch()) {
                  				
                  				echo "<tr><td style="border-style:solid;border-width:1px;border-color:#98bf21;">";			
                                  echo $results['first_name'];
                  				
                  				echo "</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;">";			
                                  echo $results['last_name'];
                  				
                  				echo "</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;">";			
                                  echo $results['trade'];
                  				
                  				echo "</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;">";			
                                  echo $results['post_code'];
                  				
                  				echo "</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;">";
                                  echo $results['telephone'];
                  				
                  				echo "</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;">";
                                  echo $results['comments'];
                  				
                  				echo "</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;">";
                  				echo $results['id'];
                                  //this its my button for delete
                  				echo("<button onclick="location.href='search.php?del=$results(id)'">delete user</button>"); 
                                  
                  				echo "</td></tr>";				
                              }
                  				echo "</table>";	
                  
                          } else {
                              echo 'Nothing found';
                          }
                  ?>

                  推荐答案

                  我会从这样的事情开始:

                  I would start with something like this:

                      $con =  new PDO( "mysql:host=".$dbHost.";"."dbname=".$dbName, $dbUsername, $dbUserPassword); 
                      $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                  
                      $sql = "DELETE FROM `table` WHERE id = ?";        
                      $q = $con->prepare($sql);
                  
                      $response = $q->execute(array($id));                
                  

                  这篇关于如何使用pdo从sql中删除数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PDO - FETCH_CLASS - 将结果作为参数传递给构造函数 下一篇:PHP:使用 PDO 从 MySQL 检索图像

                  相关文章

                  最新文章

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

                  <legend id='IWC2d'><style id='IWC2d'><dir id='IWC2d'><q id='IWC2d'></q></dir></style></legend>

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

                    1. <tfoot id='IWC2d'></tfoot>