{"id":5862543,"date":"2015-03-04T19:23:29","date_gmt":"2015-03-04T19:23:29","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/database-connect\/"},"modified":"2016-08-22T17:39:28","modified_gmt":"2016-08-22T17:39:28","slug":"database-connect","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/database-connect\/","title":{"rendered":"Database Connect"},"content":{"rendered":"<p>I have put a bit of PHP in with Insert PHP and it runs fine. Since it is a database connect, I don&#8217;t want it in the page for obvious reasons:<\/p>\n<pre><code>[insert_php]\n$$db=mysql_connect (&quot;localhost&quot;, &quot;USER&quot;, &quot;PASSWORD&quot;) or die (&#039;I cannot connect to the database because: &#039; . mysql_error());mysql_select_db (&quot;DATABASE&quot;);global $$db;$asql=mysql_query(&quot;SELECT * FROM rates WHERE r_id=&#039;1&#039;&quot;) or die(mysql_error());$arow=mysql_fetch_array($asql);\n[\/insert_php]<\/code><\/pre>\n<p>I want to put it in a file and pull it in, but when I do, it just prints the file contents. I tried this code:<\/p>\n<pre><code>[insert_php]\n$FileLocation = &quot;\/wp\/dbcon.php&quot;;\nreadfile($_SERVER[&#039;DOCUMENT_ROOT&#039;].$FileLocation);\n[\/insert_php]<\/code><\/pre>\n<p>There are additions down the page that print the data, which work fine with the first database connect statement above. For example:<\/p>\n<p>[insert_php]echo $arow[&#8216;r_reg&#8217;];[\/insert_php]<\/p>\n<p>I have tried making the file with and without the &lt;?php and ?&gt;, same results.<\/p>\n<p>Any ideas??<\/p>\n<p>Thanks in advance.<\/p>\n<p>https:\/\/wordpress.org\/plugins\/insert-php\/<\/p>\n","protected":false},"template":"","class_list":["post-5862543","topic","type-topic","status-closed","hentry","topic-tag-connection","topic-tag-database"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5862543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5862543\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5862543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}