public function Conexao() { $configuracoesDb = new Configuration(array("type" => "ini")); $configuracoesDb = $configuracoesDb->initialize()->parse('db'); $databaseFactory = new Database(); $databaseFactory->setType('mysql'); $databaseFactory->setOptions(array("host" => $configuracoesDb->database->host, "username" => $configuracoesDb->database->username, "password" => $configuracoesDb->database->password, "schema" => $configuracoesDb->database->schema)); $this->conexao = $databaseFactory->initialize(); $this->conexao = $this->conexao->connect(); }
/****** Prepare the Auto-Loader ******/ spl_autoload_register(null, false); spl_autoload_extensions('.php'); // Assign the appropriate autoloader require SYS_PATH . "/autoloader" . (CLI ? "-cli" : "") . ".php"; /****** Set the database to connect to ******/ Database::$databaseName = Config::$siteConfig['Database Name'] ? Config::$siteConfig['Database Name'] : Config::$siteConfig['Site Handle']; /****** Session Handling ******/ if (USE_SESSIONS) { session_name(SERVER_HANDLE); session_set_cookie_params(0, '/', '.' . URL_PREFIX . BASE_DOMAIN); session_start(); } /****** Prepare the Database Connection ******/ if (USE_DATABASE) { Database::initialize(Database::$databaseName); // Make sure a connection to the database was created if (Database::$database) { // Make sure the base session value used is available if (!isset($_SESSION[SITE_HANDLE])) { $_SESSION[SITE_HANDLE] = array(); } /****** Process Security Functions ******/ Security_Fingerprint::run(); /****** Setup Custom Error Handler ******/ require SYS_PATH . "/error-handler.php"; } else { // If we're installing the system if (!$url[0] == "install") { die("There was an issue connecting to the database. Likely issues: wrong user/pass credentials or the table is missing."); }
require ROUTE_PATH . "/" . $url[0] . ".php"; exit; } /****** Session Handling ******/ session_name(SITE_HANDLE); session_set_cookie_params(0, '/', '.' . BASE_DOMAIN); session_start(); // Make sure the base session value used is available if (!isset($_SESSION[SITE_HANDLE])) { $_SESSION[SITE_HANDLE] = array(); } /****** Prepare the Database Connection ******/ if (!defined("DATABASE_USER")) { die("The database has not been correctly configured."); } Database::initialize(DATABASE_NAME); // Make sure a connection to the database was created if (!Database::$database) { // If we're installing the system, we acknowledge that errors with the database will exist. if (!$url[0] == "install") { die("There was an issue connecting to the database. Likely issues: wrong user/pass credentials or the table is missing."); } } /****** Setup Custom Error Handler ******/ require SYS_PATH . "/error-handler.php"; /****** Process Security Functions ******/ Security_Fingerprint::run(); /****** Metadata Handler ******/ Metadata::load(); /****** Identify the Device (1 = mobile, 2 = tablet, 3 = device) ******/ if (!isset($_SESSION['device'])) {
<?php namespace Framework; require_once 'autoloader.php'; $database = new Database(array("type" => "mysql", "options" => array("host" => "localhost", "username" => "root", "password" => "", "schema" => "prophpmvc", "port" => "3306", "charset" => "UTF8"))); $mysql = $database->initialize(); Registry::set('database', $mysql); $mysql->sync(new User()); $elijah = new User(array("connector" => $mysql, "first" => "Chris", "last" => "Pitt", "email" => "*****@*****.**", "password" => "password", "notes" => "testtesttest", "live" => true, "deleted" => false, "created" => date("Y-m-d H:i:s"), "modified" => date("Y-m-d H:i:s"))); $elijah->save(); $all = User::all(array('last = ?' => 'Pitt')); echo '<pre>'; print_r($all); echo '</pre>'; $elijah->delete();
<?php // Prepare Values $userAccess = true; $dbName = Sanitize::variable(DATABASE_NAME); // Installation Header require dirname(ROUTE_SECOND_PATH) . "/includes/install_header.php"; // Attempt to cheat if (Database::initRoot('mysql')) { Database::exec("CREATE DATABASE IF NOT EXISTS `" . $dbName . '`'); } // Check if the standard user is properly configured after POST values were used if (Database::initialize($dbName)) { Alert::success("DB User", "The database user has access to the `" . $dbName . "` database!"); } else { Alert::error("DB User", "The `" . $dbName . "` database does not exist, or the user does not have access to it."); $userAccess = false; } // Check if the admin user is properly configured after POST values were used if (Database::initRoot($dbName)) { Alert::success("DB Admin", "The administrative database user has access to the `" . $dbName . "` database!"); } else { if ($userAccess) { Alert::error("DB Admin", "The `" . $dbName . "` database exists, but you do not have administrative privileges."); } else { Alert::error("DB Admin", "The `" . $dbName . "` database does not exist, or you do not have administrative privileges."); } } // If everything is successful: if (Validate::pass()) { // Check if the form was submitted (to continue to the next page)
Config::$dataList[] = $filename; } // Begin tracking sub-sites on the server (by capturing their config file) foreach (glob(dirname(SYS_PATH) . "/*/*/config.php") as $filename) { Config::$dataList[] = $filename; } // Capture each of the site handles in the config files foreach (Config::$dataList as $file) { $fileContents = File::read($file); $siteHandle[] = Data_Parse::between($fileContents, 'Config::$data[\'database\'][\'name\'] = "', '";'); } // Make sure the system was able to collect the appropriate site handles if ($siteHandle != array()) { foreach ($siteHandle as $sh) { if ($sh) { // Attempt to initialize another database Database::initialize($sh, Config::$siteConfig['database']['admin-user'], Config::$siteConfig['database']['admin-pass'], Config::$siteConfig['database']['host'], Config::$siteConfig['database']['type']); // Run the System Script include SYS_PATH . "/system-script.php"; echo "Ran the script for the " . $sh . " database.<br />"; } } } echo "<br /><br />Script Complete."; } else { echo ' <p>Are you sure you want to have all sites run the system-wide script "{SYS_PATH}/system-script.php" on the server?</p> <p><a class="button" href="/admin/scripts/run-system?action=run">Yes, run the script</a></p>'; } // Display the Footer require SYS_PATH . "/controller/includes/admin_footer.php";