{"id":1251,"date":"2015-02-24T13:50:44","date_gmt":"2015-02-24T13:50:44","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1251"},"modified":"2015-08-10T06:50:22","modified_gmt":"2015-08-10T06:50:22","slug":"how-can-i-make-sure-that-delete-sql-statement-in-postgres-using-php-was-successfull","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/how-can-i-make-sure-that-delete-sql-statement-in-postgres-using-php-was-successfull\/","title":{"rendered":"How can I make sure that DELETE SQL statement in Postgres using PHP was successfull?"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[1251]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/11738079\/how-can-i-make-sure-that-delete-sql-statement-in-postgres-using-php-was-successf\">question<\/a> was:<\/p>\n<p style=\"color: #222222;\">Is there a\u00a0<strong>function<\/strong>\u00a0which would return true of false based on if the DELETE SQL statement succeded or not? For example something like this:<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\n    $sql = \"DELETE FROM table WHERE id=123\";\r\n    $result = pg_query($sql);\r\n\r\n    if **function**($result)\r\n        return true;\r\n    else\r\n        return false;\r\n?&gt;<\/pre>\n<p>The answer, by <a style=\"color: #0c65a5;\" href=\"http:\/\/stackoverflow.com\/users\/1287857\/lolcoder\">LolCoder<\/a>,\u00a0was:<\/p>\n<blockquote>\n<p style=\"color: #222222;\">Use\u00a0<a style=\"color: #0c65a5;\" href=\"http:\/\/php.net\/manual\/en\/function.mysql-affected-rows.php\" rel=\"nofollow\">mysql_affected_rows()<\/a>\u00a0to get number of affected rows in mysql.<\/p>\n<p style=\"color: #222222;\">Similary for postgres, it will be\u00a0<a style=\"color: #0c65a5;\" href=\"http:\/\/php.net\/manual\/en\/function.pg-affected-rows.php\" rel=\"nofollow\">pg_affected_rows<\/a>.<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts I will will be posting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1251"}],"version-history":[{"count":2,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1251\/revisions"}],"predecessor-version":[{"id":1690,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1251\/revisions\/1690"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}