{"id":1816,"date":"2018-10-23T19:58:58","date_gmt":"2018-10-23T19:58:58","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1816"},"modified":"2022-02-17T07:14:02","modified_gmt":"2022-02-17T07:14:02","slug":"php4-connect-to-database","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/php-versions\/php4-old-code\/connecting-php4-old-code\/php4-connect-to-database","title":{"rendered":"PHP4 Connect To Database"},"content":{"rendered":"<pre>\r\n<code>\r\n\t\/\/----- CONNECT TO DATABASE -----\r\n\t$dbname = &quot;database_name&quot;;\r\n\t$dbusername = &quot;user_name&quot;;\r\n\t$dbpassword = &quot;password&quot;;\r\n\tmysql_connect(&quot;localhost&quot;, $dbusername, $dbpassword, $dbname) or die(&quot;cannot connect&quot;);\r\n\tmysql_select_db($dbname) or die(mysql_error());\t\t\/\/Select the database so it doesn&#39;t need to be specified in mysql functions\r\n<\/code><\/pre>\n<h4>\nExample Config File<br \/>\n<\/h4>\n<h5>\nconfig.php<br \/>\n<\/h5>\n<pre>\r\n<code>\r\n&lt;?php\r\n  \/\/Main Database:\r\n  $main_db_host = &#39;localhost&#39;;\t\t\t\/\/Typically &quot;localhost&quot; or IP address if on another server\r\n  $main_db_name = &#39;MY_DATABASE_NAME&#39;;\r\n  $main_db_username = &#39;USER_NAME&#39;;\r\n  $main_db_password = &#39;PASSWORD&#39;;\r\n?&gt;\r\n<\/code><\/pre>\n<h5>\nPHP Files Using The Database<br \/>\n<\/h5>\n<pre>\r\n<code>\r\ninclude_once(&#39;config.php&#39;);\r\n\r\n\/\/----- CONNECT TO DATABASE -----\r\nmysql_connect($main_db_host, $main_db_username, $main_db_password, $main_db_name) or die(&quot;cannot connect&quot;);\r\nmysql_select_db($main_db_name) or die(mysql_error());\t\t\/\/Select the database so it doesn&#39;t need to be specified in mysql functions\r\n\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/&#8212;&#8211; CONNECT TO DATABASE &#8212;&#8211; $dbname = &quot;database_name&quot;; $dbusername = &quot;user_name&quot;; $dbpassword = &quot;password&quot;; mysql_connect(&quot;localhost&quot;, $dbusername, $dbpassword, $dbname) or die(&quot;cannot connect&quot;); mysql_select_db($dbname) or die(mysql_error()); \/\/Select the database so it doesn&#39;t need to be specified in mysql functions Example Config File config.php &lt;?php \/\/Main Database: $main_db_host = &#39;localhost&#39;; \/\/Typically &quot;localhost&quot; or IP address if on another [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[155],"tags":[],"class_list":["post-1816","post","type-post","status-publish","format-standard","hentry","category-connecting-php4-old-code"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1816","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=1816"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1816\/revisions"}],"predecessor-version":[{"id":1817,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1816\/revisions\/1817"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}