{"id":274,"date":"2026-01-24T05:02:12","date_gmt":"2026-01-24T05:02:12","guid":{"rendered":"https:\/\/www.kwwd.co.uk\/blog\/?p=274"},"modified":"2026-01-24T05:19:35","modified_gmt":"2026-01-24T05:19:35","slug":"retrieve-a-single-record-row-result-from-a-mysql-database","status":"publish","type":"post","link":"https:\/\/www.kwwd.co.uk\/blog\/retrieve-a-single-record-row-result-from-a-mysql-database\/","title":{"rendered":"Retrieve A Single Record (Row) Result From A MySQL Database"},"content":{"rendered":"<p>If you just want to grab one record, or know that you are only expecting one result you can use the following code:<\/p>\n<pre><code id=\"?\" class=\"language-sql line-numbers\">\r\n&lt;?php\r\n\/\/ Connect to the database\r\n$conn = mysqli_connect(\"localhost\", \"username\", \"password\", \"database_name\", \"Port Number If Needed\");\r\n\r\n\/\/ Check connection\r\nif (!$conn) {\r\n    die(\"Connection failed: \" . mysqli_connect_error());\r\n}\r\n\r\n\/\/ Limit to one record\r\n$stmt = mysqli_prepare($conn, \"SELECT Field1, Field2, etc FROM YourTable WHERE ID = ? LIMIT 1\");\r\n\r\n\/\/ Bind and Execute our statement\r\nmysqli_stmt_bind_param($stmt, \"i\", $ID);\r\nmysqli_stmt_execute($stmt);\r\n\r\n\/\/ Get result set\r\n$result = mysqli_stmt_get_result($stmt);\r\n\r\n\/\/ Get the single row from the result set ($result) (No loop needed!)\r\n$SingleRow = mysqli_fetch_assoc($result);\r\n\r\n\/\/ 5. Use the data\r\nif ($SingleRow) {\r\n    \/\/ We have a single row returned\r\n    echo \"&lt;h1&gt;Editing: \" . htmlspecialchars($SingleRow['Field1']) . \"&lt;\/h1&gt;\";\r\n} else {\r\n    echo \"Record not found.\";\r\n}\r\n\r\nmysqli_stmt_close($stmt);\r\nmysqli_close($conn)\r\n\r\n?&gt;\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you just want to grab one record, or know that you are only expecting one result you can use the following code: &lt;?php \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,4],"tags":[31,24,9,69],"class_list":["post-274","post","type-post","status-publish","format-standard","hentry","category-mysql","category-php","tag-database","tag-mysql","tag-php","tag-records"],"_links":{"self":[{"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/posts\/274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":0,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwwd.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}