{"id":2717,"date":"2020-04-11T07:25:49","date_gmt":"2020-04-11T06:25:49","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2717"},"modified":"2022-02-17T07:13:48","modified_gmt":"2022-02-17T07:13:48","slug":"other-databases","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/database\/other-databases","title":{"rendered":"Other Databases"},"content":{"rendered":"\n<p>The wpdb object can be used to access any database and query any table. Absolutely no need to be WordPress related, which is very interesting.<\/p>\n\n\n\n<p>Simply create a new wpdb object:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $wpdb_mydb = new wpdb('username','password','database','localhost');<\/code><\/pre>\n\n\n\n<p>And use it in your functions as you do  for the wp database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  global $wpdb_mydb;\n\n  $sql = $wpdb_mydb->prepare(\"SELECT * FROM {$wpdb->prefix}my_table_name WHERE FileName = %s\", $FileName);\n  if (current_user_can('administrator'))\n    $wpdb_mydb->show_errors();\n  $Results = $wpdb_mydb->get_results($sql, ARRAY_A);\n  if (count($Results) > 0)\n    return(true);\n  else\n    return(false);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The wpdb object can be used to access any database and query any table. Absolutely no need to be WordPress related, which is very interesting. Simply create a new wpdb object: And use it in your functions as you do for the wp database:<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[165],"tags":[],"class_list":["post-2717","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2717"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2717\/revisions"}],"predecessor-version":[{"id":2718,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2717\/revisions\/2718"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}