PHP include
This post will show you how to include a PHP file inside a PHP file.
(1) I will include the DB Connection into another functional PHP file.
dbconnection.php
<?php // Connect DB $hostName ="localhost"; $userName ="jane"; $userPassword ="jane"; $database ="janedb"; $comArray = array(); $orderClause =''; $tempcompany =''; $comArray = array(); $dbConnectionStatus = new mysqli($hostName, $userName, $userPassword,$database); //Connection Error if ($dbConnectionStatus->connect_error){ die("Connection failed: " . $dbConnectionStatus->connect_error); } // Connected to Database JaneDB // Object oriented -> pointing if($dbConnectionStatus->query("SELECT DATABASE()")){ $dbSuccess =true; // $result = $dbConnectionStatus->query("SELECT DATABASE()"); $row = $result->fetch_row(); printf("Default database is %s.\n", $row[0]); $result->close(); } ?>
DB Include