{"id":280,"date":"2012-02-10T15:08:09","date_gmt":"2012-02-10T15:08:09","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=280"},"modified":"2022-02-17T07:14:04","modified_gmt":"2022-02-17T07:14:04","slug":"connect-to-database","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/connecting\/connect-to-database","title":{"rendered":"Connect To Database"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Object Oriented Style<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('config.php');\n\n\/\/----- CONNECT TO DATABASE -----\n$maindb = new mysqli($main_db_address, $main_db_username, $main_db_password, $main_db_name);\nif ($maindb->connect_error)\n{\n  die(\"Error: Unable to connect to MySQL: \" . $maindb->connect_error);\n}\n\n\/\/Turn on mysqli throwing exceptions by itself (no if() echo $maindb->error required)\nmysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">config.php<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n  \/\/Main Database:\n  $main_db_address = 'locahost';\t\t\t\/\/Typically \"localhost\" or IP address \/ URL if on another server\n  $main_db_name = 'MY_DATABASE_NAME';\n  $main_db_username = 'USER_NAME';\n  $main_db_password = 'PASSWORD';\n?><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Procedural&nbsp;Style<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('config.php');\n\n\/\/----- CONNECT TO DATABASE -----\n$dblink = mysqli_connect($main_db_address, $main_db_username, $main_db_password, $main_db_name);\nif (!$dblink)\n{\n  echo \"Error: Unable to connect to MySQL.\" . PHP_EOL;\n  echo \"Debugging errno: \" . mysqli_connect_errno() . PHP_EOL;\n  echo \"Debugging error: \" . mysqli_connect_error() . PHP_EOL;\n  die();\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Object Oriented Style config.php Procedural&nbsp;Style<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-connecting"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/280","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=280"}],"version-history":[{"count":13,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"predecessor-version":[{"id":2996,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/280\/revisions\/2996"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}