首页 \ 问答 \ 删除记录,如果它存在于php / PDO中[重复](Deleting record if it exists in php/PDO [duplicate])

删除记录,如果它存在于php / PDO中[重复](Deleting record if it exists in php/PDO [duplicate])

这个问题在这里已有答案:

我有一些代码从MySQL数据库中删除记录,但即使记录不存在,我也会收到成功消息。 如果记录不存在但找不到符合我代码的记录,我已经搜索了生成消息的方法。

我的代码是:

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
    /*** echo a message saying we have connected ***/
    //echo 'Connected to database<br />';
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "DELETE FROM ukgh WHERE telephone = :telephone";
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam(':telephone', $telephone, PDO::PARAM_STR);   
    $stmt->execute(); 

    /*** close the database connection ***/
    $dbh = null;
}
catch(PDOException $e) {
    echo $e->getMessage();
}
// once processing is complete
// show success message
echo 'Success - The record for ' . $telephone . ' has been deleted.';
?>

请注意Fred-ii-你提到的答案是正确的,但我问的问题中的术语是不同的。 我问如何确保我删除的RECORD存在。 我没有问如何检查一行是否存在,并且当我在寻找现有的RECORD时,我从未想过要搜索有关现有ROW的任何内容。 对于像你这样的专家来说,一行可能和唱片一样,但是我和其他像我这样不那么开明的人从来没有听过一个叫做行的记录。 祝福,Tog


This question already has an answer here:

I have some code that deletes a record from a MySQL database, but I get the success message even if the record does not exist. I have searched for ways of producing a message if the record does not exist but cannot find one that works with my code.

My code is:

try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
    /*** echo a message saying we have connected ***/
    //echo 'Connected to database<br />';
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "DELETE FROM ukgh WHERE telephone = :telephone";
    $stmt = $dbh->prepare($sql);
    $stmt->bindParam(':telephone', $telephone, PDO::PARAM_STR);   
    $stmt->execute(); 

    /*** close the database connection ***/
    $dbh = null;
}
catch(PDOException $e) {
    echo $e->getMessage();
}
// once processing is complete
// show success message
echo 'Success - The record for ' . $telephone . ' has been deleted.';
?>

Note to Fred-ii- The answer you referred to is correct, but the terminology in the question I asked was different. I asked how to ensure the RECORD I was deleting existed. I did not ask how to check if a row exists, and would never have thought to search for anything about an existing ROW when I was looking for an existing RECORD. To some experts like yourself a row may be the same as a record, but I and possibly other less enlightened people like me have never heard a record called a row. Best wishes, Tog


原文:https://stackoverflow.com/questions/44305738
更新时间:2022-02-25 21:02

最满意答案

我会尝试在自定义控件中创建网格视图和按钮,然后在需要它的任何页面上重新使用自定义控件。 如果需要自定义任何内容,则可以定义在包含自定义控件的页面中设置的属性,例如提供给网格视图的数据源。

请参阅: http//msdn.microsoft.com/en-us/library/y6wb1a0e(v = vs.100).aspx


I would try creating the grid view and buttons within a Custom Control, and then re-using the custom control across any pages that need it. You can define properties set in the pages containing the custom control if you need to customize anything, like the data source provided to the grid view.

See: http://msdn.microsoft.com/en-us/library/y6wb1a0e(v=vs.100).aspx

相关问答

更多
  • 请参阅Java和.NET技术/框架类似的答案 See this answer with analogues of Java and .NET technologies/frameworks
  • 最好的选择是DotNetNuke ,如果你想使用.Net 2.0,那么你可以选择旧版本的DNN,并且你需要搜索该DNN的插件。 另一种选择是Umbraco CMS。 它在社区中也是众所周知的。 还有第三方付费版本的CMS可以具有您想要的功能。 Best option is DotNetNuke, if you want to go for .Net 2.0 then you can choose older version of DNN and you need to search plugins for ...
  • 你没错。 ASP.Net是编译语言,其中VBScript是Scripting Runtime,混淆来自ASP(也称为Classic ASP),它使用Scripting Languages来支持它的服务器端脚本功能。 是的,两者在语法上有相似之处(如果使用VB.Net),但ASP.Net是构建企业级Web应用程序的更强大和结构化的方法。 另见asp和asp.net之间的区别 You are not wrong. ASP.Net is compiled language where as VBScript is ...
  • 我会尝试在自定义控件中创建网格视图和按钮,然后在需要它的任何页面上重新使用自定义控件。 如果需要自定义任何内容,则可以定义在包含自定义控件的页面中设置的属性,例如提供给网格视图的数据源。 请参阅: http : //msdn.microsoft.com/en-us/library/y6wb1a0e(v = vs.100).aspx I would try creating the grid view and buttons within a Custom Control, and then re-using ...
  • 我会选择Tipsy: http : //plugins.jquery.com/project/tipsy 演示: http : //onehackoranother.com/projects/jquery/tipsy/ I would go with Tipsy: http://plugins.jquery.com/project/tipsy Demo at: http://onehackoranother.com/projects/jquery/tipsy/
  • ViewState是允许在页面回传中保留状态值的机制。 网络是无状态的。 但在ASP.NET中,页面状态会自动保留在页面中。这是通过使用ViewState.In ViewState将值加密并保存在隐藏控件中。 当您查看使用ViewState的页面源代码(在浏览器中)时,您可能会看到隐藏的视图状态 输入将看起来像这样: ...
  • Web部件:Web部件是构建在ASP.NET 2.0中用于构建高度可定制的门户式页面的框架。用户可以在浏览器中为每个用户进行自定义用户设置。例如,为浏览器中的每个控件最小化,最大化,关闭等。 http://www.csharpcorner.com/UploadFile/a_anajwala/Building_WebParts.mht08042005042119AM/Building_WebParts.mht.aspx?ArticleID=62ffd1b4-98fa-41cc-9512-9b0637e91ee ...
  • 你的问题非常广泛,所以我只会给出一个很好的实现方法。 对于菜单系统,您可以创建两个Div元素,一个用于菜单,另一个用于内容。 菜单div应包含一个Action ,它调用JavaScript以使用Controller返回的Partial View替换主Div的内容。 在你的_Layout页面中你可以这样 @Html.Action("RetrieveSideBar", "SideBar", new { area = "" })
    ...
  • 看看sensenet http://sensenet.codeplex.com/ 我正在尝试它,因为我也在寻找.net / asp.net解决方案。 这看起来很有希望。 到目前为止,它似乎是我可以使用的东西。 唯一的问题是GPL许可证,但我看到了与之相关的协议。 即你想与其他软件合作使用它。 Have a look at sensenet http://sensenet.codeplex.com/ I am trying it at the moment as I am also looking for a ...
  • 我们使用Telerik Radeditor,并且它表现出色。 微软也在他们的MSDN网站上使用它。 这不是免费的,但值得投资。 http://demos.telerik.com/aspnet-ajax/editor/examples/overview/defaultcs.aspx we use the Telerik Radeditor, and it performs great. Microsoft also uses it on their MSDN website. It's not free, b ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)