{"id":47,"date":"2014-09-09T08:32:00","date_gmt":"2014-09-09T08:32:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2014\/09\/09\/phpbb-api-accessing-database-and-performing-sql-queries\/"},"modified":"2021-02-22T01:02:43","modified_gmt":"2021-02-22T01:02:43","slug":"phpbb-api-accessing-database-and-sql-queries","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2014\/09\/phpbb-api-accessing-database-and-sql-queries.html","title":{"rendered":"phpBB API &#8211; Accessing Database and Performing Sql Queries"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"clear: both; text-align: center;\"><\/div>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/phpbb-logo.png\"><img loading=\"lazy\" decoding=\"async\" title=\"phpBB Logo\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/phpbb-logo.png\" alt=\"phpBB Logo\" width=\"320\" height=\"148\" border=\"0\" \/><\/a><\/div>\n<p>In my two previous posts, <a href=\"http:\/\/www.tech-and-dev.com\/2014\/08\/phpbb-api-logging-in-and-logging-out-a-user.html\" target=\"_blank\" rel=\"noopener\">phpBB API &#8211; Logging In And Logging Out a User<\/a> and <a href=\"http:\/\/www.tech-and-dev.com\/2014\/08\/phpbb-api-auto-login-user-without-password.html\" target=\"_blank\" rel=\"noopener\">phpBB API &#8211; Auto Login a User Without a Password<\/a>, I used phpBB API to perform some API functionalities such as logging in a user without a password and logging out a user.<\/p>\n<p>In this post, I will use the phpBB API to perform some SQL queries on the phpBB database to change the user&#8217;s password and verify a user.<\/p>\n<h2 style=\"text-align: left;\">Changing a User&#8217;s Password<\/h2>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">&lt;?php<br \/>\ndefine(&#8216;IN_PHPBB&#8217;, true);\/\/Must be defined<br \/>\n$phpbb_root_path = &#8216;..\/phpBB3\/&#8217;;\/\/your forum directory location<br \/>\n$phpEx = substr(strrchr(__FILE__, &#8216;.&#8217;), 1);<br \/>\nrequire_once($phpbb_root_path . &#8216;common.&#8217; . $phpEx); <\/span><\/p>\n<p>function phpbbChangePassword($username, $newPassword)<br \/>\n{<br \/>\nglobal $phpbb_root_path, $phpEx, $user, $db,$table_prefix;<br \/>\n$newPassword = phpbb_hash($newPassword);<\/p>\n<p>$sql = &#8220;UPDATE `&#8221; . $table_prefix . &#8220;users` SET user_password = &#8216;&#8221; . $password . &#8220;&#8216; WHERE username = &#8216;&#8221; . $username . &#8220;&#8216;&#8221;;<br \/>\n$db-&gt;sql_query($sql);<br \/>\n$stmt-&gt;close();<br \/>\n}<\/p>\n<p>\/\/Changing Password for user &#8220;Test&#8221;<br \/>\n$username = &#8220;Test&#8221;;<br \/>\n$newPassword = &#8220;myNewPassword&#8221;;<br \/>\nphpbbChangePassword($username, $newPassword);<\/p>\n<p>?&gt;<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">Changing user&#8217;s status to verified<\/h2>\n<blockquote><p><span style=\"font-family: 'Courier New',Courier,monospace;\">&lt;?php<br \/>\ndefine(&#8216;IN_PHPBB&#8217;, true);\/\/Must be defined<br \/>\n$phpbb_root_path = &#8216;..\/phpBB3\/&#8217;;\/\/your forum directory location<br \/>\n$phpEx = substr(strrchr(__FILE__, &#8216;.&#8217;), 1);<br \/>\nrequire_once($phpbb_root_path . &#8216;common.&#8217; . $phpEx);<\/span><br \/>\n<span style=\"font-family: 'Courier New',Courier,monospace;\"><br \/>\n<\/span><span style=\"font-family: 'Courier New',Courier,monospace;\">function phpbbVerifyUser($username)<br \/>\n{<br \/>\nglobal $phpbb_root_path, $phpEx, $user, $db, $table_prefix;<br \/>\n$userType = USER_NORMAL;<br \/>\n$sql = &#8220;UPDATE `&#8221; . $table_prefix . &#8220;users` SET user_type = &#8216;&#8221; . $userType . &#8220;&#8216; WHERE username = &#8216;&#8221; . $username . &#8220;&#8216;&#8221;;<br \/>\n$db-&gt;sql_query($sql);<br \/>\n} <\/span><\/p>\n<p>\/\/Verifying User &#8220;Test&#8221;<br \/>\n$username = &#8220;Test&#8221;;<br \/>\nphpbbVerifyUser($username);<\/p>\n<p>?&gt;<\/p><\/blockquote>\n<p><b>Any questions, please let me know!<\/b><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In my two previous posts, phpBB API &#8211; Logging In And Logging Out a User and phpBB API &#8211; Auto Login a User Without a Password, I used phpBB API to perform some API functionalities such as logging in a user without a password and logging out a user. In this post, I will use [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[63,45,22,62],"tags":[],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-api","category-mysql","category-php","category-phpbb3"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":1,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"predecessor-version":[{"id":270,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/47\/revisions\/270"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}