/** * Create the controller action service * * @param ContainerInterface $container * @return \Ultradata\Home\Controller\HomePageAction */ public function __invoke(ContainerInterface $container) { // set up database connection $config = $this->getConfig($container); \RedBeanPHP\R::setup(sprintf("mysql:host=%s;dbname=%s", $config['host'], $config['dname']), $config['username'], $config['password']); $router = $container->get('Zend\\Expressive\\Router\\RouterInterface'); $template = $container->has('Zend\\Expressive\\Template\\TemplateRendererInterface') ? $container->get('Zend\\Expressive\\Template\\TemplateRendererInterface') : null; $controller = new Controller($router, $template); return $controller; }
public function setupMySql($host, $name, $user, $password) { $this->dbHost = $host; $this->dbName = $name; $this->dbUser = $user; $this->dbPassword = $password; R::setup('mysql:host=' . $host . ';dbname=' . $name, $user, $password); return $this; }
public function run() { global $slim; $view = new \Slim\Views\Smarty(); $view->parserExtensions = ['vendor/slim/views/SmartyPlugins']; $this->slim = $slim = new Slim(['view' => $view, 'templates.path' => 'views']); $this->slim->setName('um'); R::setup('mysql:host=localhost;dbname=um', 'root', ''); // add middleware $this->addMiddleware(new AuthMiddleware()); $this->route = new Route($this->slim); $this->route->run(); $this->slim->run(); }
public static function setupBeforeClass() { try { R::setup('sqlite:tests.db'); } catch (Exception $ex) { } }
public static function DBSetup() { $config = \Config::getSection("DB1"); if (!self::$CONNECTED) { R::setup('mysql:host=localhost;dbname=' . $config['dbname'], $config['username'], $config['password']); self::$CONNECTED = true; } }
public function register(Container $app) { $app['db'] = function () use($app) { $options = array('dsn' => null, 'username' => null, 'password' => null, 'frozen' => false); if (isset($app['db.options'])) { $options = array_replace($options, $app['db.options']); } R::setup($options['dsn'], $options['username'], $options['password'], $options['frozen']); }; }
public function register(Container $c) { $settings = $c["settings"]; $options = ['dsn' => null, 'username' => null, 'password' => null, 'frozen' => false]; if (isset($settings["redbean.setup"])) { $options = array_merge($options, $settings["redbean.setup"]); } $c["redbean"] = R::setup($options["dns"], $options["username"], $options["password"], $options["frozen"]); $c["redbean.helper"] = new \CodePasha\RedBean\Support\RedBeanHelper(); R::getRedBean()->setBeanHelper($c["redbean.helper"]); R::setAutoResolve(true); }
/** * Connect to existing database handle with RedBeans */ public static function connectExisting() { static $connected = null; if (!$connected) { R::setup(connect::$dbh); $connected = true; } $freeze = conf::getMainIni('rb_freeze'); if ($freeze == 1) { R::freeze(true); } }
/** * Register the service provider. * * @return void */ public function register() { //Get DB configs from app/config/database.php $default = Config::get('database.default'); $connections = Config::get('database.connections'); $db_host = $connections[$default]['host']; $db_user = $connections[$default]['username']; $db_pass = $connections[$default]['password']; $db_name = $connections[$default]['database']; $db_driver = $connections[$default]['driver']; //Run the R::setup command based on db_type if ($default != 'sqlite') { $conn_string = $db_driver . ':host=' . $db_host . ';dbname=' . $db_name; } else { $conn_string = $db_driver . ':' . $db_name; } R::setup($conn_string, $db_user, $db_pass); }
public function run() { global $slim; $view = new \Slim\Views\Smarty(); $view->parserExtensions = ['vendor/slim/views/SmartyPlugins']; $this->slim = $slim = new Slim(['view' => $view, 'templates.path' => 'views']); $this->slim->setName('um'); R::setup('mysql:host=localhost;dbname=lighting_durag', 'root', ''); // R::setup('mysql:host=localhost;dbname=lighting_durag', 'root', 'mysql@umi'); R::ext('xdispense', function ($type) { return R::getRedBean()->dispense($type); }); // add middleware $this->addMiddleware(new AuthMiddleware()); $this->route = new Route($this->slim); $this->route->run(); $this->slim->run(); }
protected static function init() { if (self::$_inited) { return; } $c = static::conf(); shuffle($c['write']); shuffle($c['read']); self::$_mcs = $c['write']; self::$_scs = array_merge($c['read'], $c['write']); R::setup(); foreach (self::$_mcs as $i => $c) { R::addDatabase("write:{$i}", sprintf('mysql:host=%s;port=%d;dbname=%s', $c['host'], $c['port'], $c['dbname']), $c['username'], $c['password']); } foreach (self::$_scs as $i => $c) { R::addDatabase("read:{$i}", sprintf('mysql:host=%s;port=%d;dbname=%s', $c['host'], $c['port'], $c['dbname']), $c['username'], $c['password']); } self::$_inited = true; }
public function __construct($config) { $this->config = $config; R::setup('mysql:host=localhost;dbname=spider', 'root', 'jun'); }
<?php namespace Midna; use RedBeanPHP\R; use Telegram\Bot\Api; require_once __DIR__ . '/../../vendor/autoload.php'; define('MIDNA_TOKEN', 'xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); define('MIDNA_HOOK', 'https://example.com/path/to/this/file.php'); define('MIDNA_CERT', '/path/to/your/ssl/certificate.pem'); $telegram = new Api(MIDNA_TOKEN); R::setup('sqlite:' . __DIR__ . '/../../database/database.db'); $telegram->addCommand(new Commands\Start()); $telegram->addCommand(new Commands\Help()); $telegram->commandsHandler(true); if (php_sapi_name() == 'cli') { if ($argv[1] == 'start') { print "Starting Midna" . PHP_EOL; $bean = R::dispense('messages'); $bean->message_id = 0; $bean->message_date = 0; R::store($bean); $telegram->setWebhook(['url' => MIDNA_HOOK, 'certificate' => MIDNA_CERT]); } else { if ($argv[1] == 'stop') { print "Stopping Midna" . PHP_EOL; $telegram->removeWebhook(); } } exit; }
<?php // set the timezone date_default_timezone_set('Europe/London'); // ----------------------------------------------------------------------------- // Service factories // ----------------------------------------------------------------------------- // monolog $container['logger'] = function ($c) { $settings = $c['settings']['logger']; $logger = new \Monolog\Logger($settings['name']); $logger->pushProcessor(new \Monolog\Processor\UidProcessor()); $logger->pushHandler(new \Monolog\Handler\StreamHandler($settings['path'], \Monolog\Logger::DEBUG)); return $logger; }; $container['dsn'] = function ($c) { $settings = $c['settings']['database']; $dsn = $settings['driver'] . ':host=' . $settings['host'] . (!empty($settings['port']) ? ';port=' . $settings['port'] : '') . ';dbname=' . $settings['database']; return $dsn; }; $frozen = $container['settings']['database']['frozen']; //with namespace Model define('REDBEAN_MODEL_PREFIX', '\\App\\Models\\'); \RedBeanPHP\R::setup($container['dsn'], $container['settings']['database']['username'], $container['settings']['database']['password'], $frozen); // database mysqli connection $container['database'] = function ($c) { $settings = $c['settings']['database']; $connection = new \PDO($c['dsn'], $settings['username'], $settings['password']); //$connection = new mysqli($settings['host'], $settings['username'], $settings['password'], $settings['database']); return $connection; };
$logger = $c->get('logger'); $session = $c->get('session'); $settings = $c->get('settings')['facebook']; $connect = new Connect($settings, $session, $logger); return $connect; }; $container['database'] = function ($c) { $logger = $c->get('logger'); $settings = $c->get('settings')['database']; define('QUESTION', 'quiz_question'); define('ANSWER', 'quiz_answer'); define('QUIZ', 'quiz_quiz'); define('USER', 'quiz_user'); // Create an extension to by-pass security check in R::dispense R::ext('xdispense', function ($type) { return R::getRedBean()->dispense($type); }); R::renameAssociation(['quiz_answer_quiz_question' => 'quiz_answer_question', 'quiz_answer_quiz_quiz' => 'quiz_answer_quiz', 'quiz_question_quiz_quiz' => 'quiz_question_quiz']); define('REDBEAN_MODEL_PREFIX', '\\App\\Model\\'); $connectionString = 'mysql:host=' . $settings['host'] . ';dbname=' . $settings['dbname']; R::setup($connectionString, $settings['username'], $settings['password']); R::useWriterCache(true); //R::debug(true); // // NEVER REMOVE THIS! R::freeze(true); return R::getRedBean(); }; $container['quiz'] = function ($c) { $database = $c->get('database'); return new QuizService(); };
public static function setDBConntction() { \RedBeanPHP\R::setup('mysql:host=localhost;dbname=bookmark', 'root', 'ltqpsmr7'); }
<?php use RedBeanPHP\R; use Saft\Data\SerializerFactoryImpl; use Saft\Rdf\ArrayStatementIteratorImpl; use Saft\Rdf\LiteralImpl; use Saft\Rdf\NamedNodeImpl; use Saft\Rdf\StatementImpl; // setup Database connection try { R::setup('sqlite:./geo-info.sqlite3'); } catch (RedBeanPHP\RedException $e) { } /** * Generates CSV file * * @param string $filename * @param array $infoArray */ function createCSVFile($filename, array $infoArray) { $file = fopen($filename, 'w'); $copy = $infoArray; if (0 == count($infoArray)) { throw new Exception('Given $infoArray parameter is empty. Aborting CSV file generation...'); } fputcsv($file, array_keys(array_shift($copy))); $i = 0; foreach ($infoArray as $value) { fputcsv($file, $value); ++$i;
<?php //turn all reporting on error_reporting(E_ALL); ini_set('display_errors', 1); require 'vendor/autoload.php'; \RedBeanPHP\R::setup('mysql:host=localhost;dbname=db_smi', 'root', 'root'); $logWriter = new \Slim\LogWriter(fopen(__DIR__ . '/logs/log-' . date('Y-m-d', time()), 'a')); $customConfig = array(); \Slim\Slim::registerAutoloader(); $app = new \Slim\Slim(array('log.writer' => $logWriter, 'custom' => $customConfig)); /* $app->add(new \Slim\Middleware\HttpBasicAuthentication([ "realm" => "Protected", "relaxed" => array("localhost"), "users" => [ "root" => "r0Ot_C0n643" ] ])); */ //Including all resources foreach (glob("resources/*.php") as $filename) { require_once $filename; } $app->run();
* * @author Jairo E. Vengoechea R. * */ session_start(); /** @constant __PUBLIC__ Public folder*/ define('__PUBLIC__', dirname(__FILE__)); /** @constant __ROOT__ Root folder*/ define('__ROOT__', dirname(dirname(__FILE__))); /** @constant __DEV__ */ define('__DEV__', true); /** Config */ require_once __ROOT__ . '/routing/config.php'; //Importing config.php require_once __ROOT__ . '/core/MCN.php'; use MCN\MCN; //Importing Bower Includer require_once __ROOT__ . '/core/Includer.php'; //vendors require_once __ROOT__ . '/vendor/autoload.php'; //initiate DB use RedBeanPHP\R; R::setup('mysql:host=' . $config['dbhost'] . ';dbname=' . $config['dbname'], $config['dbuser'], $config['dbpass']); R::setAutoResolve(TRUE); //initialising the app $MCN = new MCN(); $includes = $MCN->includes(); foreach ($includes as $inc) { require_once $inc; } $MCN->route();
<?php /** * RedBean service provider * @return \RedBeanPHP\ToolBox */ use ZigiPhp\App; return function () { return \RedBeanPHP\R::setup(App::getConfig('redbean')['dsn'], App::getConfig('redbean')['username'], App::getConfig('redbean')['password'], App::getConfig('redbean')['frozen']); };
$jsonResponse = new JsonResponse(); require_once 'helpers.php'; // Must come after $jsonResponse exists. // Catch Exception if connection to DB failed function exceptionHandler($exception) { global $jsonResponse; header('Content-Type: application/json'); http_response_code(503); $jsonResponse->message = 'API Error.'; $jsonResponse->data = $exception->getMessage(); $jsonResponse->trace = $exception->getTrace(); echo $jsonResponse->asJson(); } set_exception_handler('exceptionHandler'); R::setup('sqlite:' . __DIR__ . '/taskboard.db'); R::setAutoResolve(TRUE); createInitialUser(); $app->notFound(function () use($app, $jsonResponse) { $app->response->setStatus(404); $jsonResponse->message = 'Matching API call Not found.'; $app->response->setBody($jsonResponse->asJson()); }); $app->get('/authenticate', function () use($app, $jsonResponse) { if (validateToken()) { $jsonResponse->message = 'Token is authenticated.'; } $app->response->setBody($jsonResponse->asJson()); }); require_once 'mailFactory.php'; require_once 'userRoutes.php';
use router\Router; use RedBeanPHP\R; use http\HttpContext; use handler\Handlers; use handler\json\JsonHandler; use handler\http\HttpStatusHandler; use handler\json\Json; use handler\http\HttpStatus; use http\HttpSession; use auth\service\HttpAuth; use auth\provider\HtpasswdProvider; include __DIR__ . '/../vendor/autoload.php'; include 'Model_Post.php'; // setup database R::setup('sqlite:../db/dbfile.db'); // all dates in UTC timezone date_default_timezone_set("UTC"); ini_set('date.timezone', 'UTC'); $router = new Router(); $auth = new HttpAuth(new HtpasswdProvider('../db/.htpasswd'), 'Posts admin'); $handlers = Handlers::get(); $handlers->add(new JsonHandler()); $handlers->add(new HttpStatusHandler()); /** * Fetch all posts * * @return Json array with all posts */ $router->route('posts-list', '/posts', function () { $result = [];
<?php include 'vendor/autoload.php'; use RedBeanPHP\R; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Output\ConsoleOutput; R::setup('sqlite:db/ppm.db'); $output = new ConsoleOutput(); $style = new OutputFormatterStyle('white', 'black', array('bold')); if (!isset($argv[1])) { $output->writeln(Cpm\message::USAGE); exit; } $q = $argv[1]; $datas = R::findAll('repo', ' name LIKE ? order by download_total desc', ['%' . $q . '%']); $a = array(); foreach ($datas as $data) { $output->getFormatter()->setStyle('bold', $style); $output->writeln('<bold>' . $data->name . '</bold>' . ' ' . $data->description); $output->writeln($data->keywords); }
<?php require './vendor/autoload.php'; use RedBeanPHP\R; $faker = Faker\Factory::create(); R::setup('mysql:host=localhost;dbname=my_fake_db', 'username', 'password'); for ($i = 0; $i < 500; $i++) { $student = R::dispense('student'); $student['first_name'] = $faker->firstName; $student['last_name'] = $faker->lastName; $student['address'] = $faker->address; $student['phone'] = $faker->phoneNumber; $student['email'] = $student['first_name'] . "@" . $faker->freeEmailDomain; $student['ccn'] = $faker->creditCardNumber; $student->setMeta('cast.ccn', 'string'); $student['cce'] = $faker->creditCardExpirationDateString; $student['essay'] = $faker->text($maxNbChars = 4000); $student['dob'] = $faker->date; R::store($student); echo "Added " . $student['first_name'] . " " . $student['last_name'] . "\n"; }
<?php require "vendor/autoload.php"; use LouisLam\CRUD\SlimLouisCRUD; use RedBeanPHP\R; /* * 1. Setup a Database Connection (Support MySQL, SQLite etc.) * Please refer to: http://www.redbeanphp.com/connection */ R::setup('sqlite:dbfile.db'); /* * 2. Create a SlimLouisCRUD instance. */ $crud = new SlimLouisCRUD(); /* * 3. Add handlers */ $crud->add("user", function () use($crud) { $crud->showFields(["id", "name", "password", "email"]); }); $crud->add("book", function () use($crud) { $crud->showFields(["id", "title", "date"]); }); /* * 4. Run the application */ $crud->run();
<?php require './vendor/autoload.php'; use RedBeanPHP\R; R::setup('sqlite:smplog.db'); $app = new Slim\App(); require 'app-setup.php'; Auth::CreateInitialAdmin($container); Auth::CreateJwtKey(); $app->post('/admin/login', 'Auth:login'); $app->post('/admin/logout', 'Auth:logout'); $app->post('/admin/authenticate', 'Auth:authenticate'); $app->get('/admin/authors', 'Admin:getAuthors'); $app->post('/admin/authors', 'Admin:addAuthor'); $app->get('/admin/authors/{id}', 'Admin:getAuthor'); $app->post('/admin/authors/{id}', 'Admin:updateAuthor'); $app->delete('/admin/authors/{id}', 'Admin:removeAuthor'); $app->post('/admin/details', 'Admin:updateDetails'); $app->get('/admin/posts', 'Admin:getPosts'); // (by requesting author/user) $app->post('/admin/posts', 'Admin:addPost'); $app->post('/admin/posts/{id}', 'Admin:updatePost'); $app->delete('/admin/posts/{id}', 'Admin:removePost'); $app->post('/admin/posts/{id}/publish', 'Admin:publishPost'); $app->post('/admin/posts/{id}/unpublish', 'Admin:unpublishPost'); $app->get('/details', 'Details:getDetails'); $app->get('/posts', 'Posts:getPosts'); $app->get('/posts/{slug}', 'Posts:getPost'); $app->get('/authors', 'Authors:getAuthors'); $app->get('/authors/{id}', 'Authors:getAuthor'); $app->get('/authors/{id}/posts', 'Authors:getPosts');
/** * Connect to database with a connection * @param resource $dsn */ public function __construct($dbh, $freeze = true) { R::setup($dbh); R::freeze($freeze); connect::$dbh = $dbh; }
<?php require 'vendor/autoload.php'; define('APP_PATH', dirname(__DIR__)); session_cache_limiter(false); session_start(); $app = new \Slim\Slim(); use RedBeanPHP\R; R::setup('mysql:host=localhost;dbname=naughtyfire', 'root', 'nitoryolai'); $app = new \SlimController\Slim(array('controller.class_prefix' => '\\Naughtyfire\\Controller', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => 'php')); $app->addRoutes(array('/' => 'Home:index', '/holiday/create' => 'Home:createHoliday', '/settings' => 'Home:settings', '/settings/update' => 'Home:updateSettings', '/recepients' => 'Home:recepients', '/recepients/new' => 'Home:newRecepient', '/recepients/create' => 'Home:createRecepient', '/notify' => 'Notifier:notify')); $view = $app->view(); $view->setTemplatesDirectory('./templates'); $app->run();
public function setupDB() { $config = \Config::getSection("DB1"); R::setup("mysql:host={$config['host']};dbname={$config['dbname']}", "{$config['username']}", "{$config['password']}"); }
protected function _loadDb() { /** @var Config $config */ $config = $this->getContainer()->get('settings'); R::setup($config->get('db.dsn'), $config->get('db.username'), $config->get('db.password'), $config->get('db.frozen')); }