setup() public static method

Kickstarts redbean for you. This method should be called before you start using RedBean. The Setup() method can be called without any arguments, in this case it will try to create a SQLite database in /tmp called red.db (this only works on UNIX-like systems).
public static setup ( string $dsn = NULL, string $username = NULL, string $password = NULL, boolean $frozen = FALSE ) : ToolBox
$dsn string Database connection string
$username string Username for database
$password string Password for database
$frozen boolean TRUE if you want to setup in frozen mode
return ToolBox
<?php

ini_set('max_execution_time', 0);
require 'vendor/autoload.php';
require_once 'vendor/fzaninotto/faker/src/autoload.php';
$faker = Faker\Factory::create('fr_FR');
use RedBeanPHP\Facade as R;
R::setup('mysql:host=localhost;dbname=gsb_cost_managment', 'root', 'pwsio');
R::exec('CREATE VIEW visitor AS SELECT * FROM gsb_human_ressources.employee WHERE employee.job_id=3');
$status = R::dispense('status');
$status->libelle = 'Créée';
R::store($status);
$status = R::dispense('status');
$status->libelle = 'Clôturée';
R::store($status);
$status = R::dispense('status');
$status->libelle = 'Validée';
R::store($status);
$status = R::dispense('status');
$status->libelle = 'Mise en paiement';
R::store($status);
$status = R::dispense('status');
$status->libelle = 'Remboursée';
R::store($status);
for ($i = 0; $i < 12960; $i++) {
    $cost_sheet = R::dispense('costsheet');
    $cost_sheet->month = $faker->month;
    $cost_sheet->visitor = R::findOne('visitor', 'id=?', [$faker->numberBetween($min = 1, $max = 540)]);
    $cost_sheet->status = R::findOne('status', 'id=?', [$faker->numberBetween($min = 1, $max = 5)]);
    $cost_sheet->justification_number = $faker->randomDigitNotNull;
    $cost_sheet->valid_amount = $faker->randomNumber($nbDigits = 3);
Esempio n. 2
0
<?php

// Error reporting
//error_reporting(E_ALL ^ E_NOTICE);
// SlimPHP portable route fix
$_SERVER['SCRIPT_NAME'] = preg_replace('/public\\/index\\.php$/', 'index.php', $_SERVER['SCRIPT_NAME'], 1);
// RedBeanPHP alias fix
use RedBeanPHP\Facade as R;
// Load Config
require 'app/config.php';
// Autoload
require 'vendor/autoload.php';
// RedBeanPHP setup
R::setup('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD);
R::freeze(DB_FREEZE);
// Slim app instance
$app = new \Slim\Slim();
// Slim Config
$app->config(['templates.path' => 'app/views', 'debug' => APP_DEBUG]);
// Set webroot for portable
$app->hook('slim.before', function () use($app) {
    $app->wroot = $app->request->getUrl() . $app->request->getRootUri();
    $app->view()->appendData(array('wroot' => $app->wroot));
});
// HybridAuth instance
$app->container->singleton('hybridInstance', function ($app) {
    $config = ["base_url" => $app->wroot . "/cb", "providers" => ["Facebook" => ["enabled" => true, "keys" => ["id" => FB_ID, "secret" => FB_SECRET], "scope" => "email, user_about_me, user_birthday, user_location", "trustForwarded" => false], "Twitter" => ["enabled" => true, "keys" => ["key" => TW_KEY, "secret" => TW_SECRET]]], "debug_mode" => HYBRIDAUTH_DEBUG_MODE, "debug_file" => HYBRIDAUTH_DEBUG_FILE];
    $instance = new Hybrid_Auth($config);
    return $instance;
});
// Auth Check
Esempio n. 3
0
<?php

// 05-composer
require "vendor/autoload.php";
use RedBeanPHP\Facade as R;
// Connexion à la page de donnée.
R::setup("sqlite:" . __DIR__ . "/../users.db");
// Configuration de Twig
$loader = new Twig_Loader_Filesystem("templates");
$twig = new Twig_Environment($loader);
// Ajout des filtres md5 et strtolower qui sont les fonctions PHP du même nom.
$twig->addFilter(new Twig_SimpleFilter("strtolower", "strtolower"));
$twig->addFilter(new Twig_SimpleFilter("md5", "md5"));
// variables globales
$titre = "He-Arc";
$base = dirname($_SERVER["SCRIPT_NAME"]);
// Lecture de l"URL
list($uri) = explode("?", $_SERVER["REQUEST_URI"], 2);
// on ôte le prefix même que RewriteBase.
$uri = substr($uri, strlen($base));
// on match.
$matches = [];
if (preg_match("#^/(?<page>[^/]+)/(?<slug>[^/]+)/?#", $uri, $matches)) {
    $page = $matches["page"];
    $args = [$matches["slug"]];
} else {
    $page = "accueil";
    $args = [];
}
// Front controller
if (function_exists($page)) {
Esempio n. 4
0
<?php

require_once 'tests/vendor/autoload.php';
require_once '_Scripts.php';
// REDBEAN CONFIGURATION
use RedBeanPHP\Facade as RedBean;
RedBean::setup('mysql:host=localhost;dbname=phpback_test', 'root', '');
class TestCase extends PHPUnit_Extensions_Selenium2TestCase
{
    protected $mysqli;
    public function setUp()
    {
        $this->setHost('localhost');
        $this->setPort(4444);
        $this->setBrowser('firefox');
        $this->setBrowserUrl('http://localhost:8080/');
        $this->mysqli = new mysqli('localhost', 'root', '', 'phpback_test');
        Scripts::setInstance($this);
    }
    public function getFields($array)
    {
        $fields = array();
        foreach ($array as $value) {
            $fields[$value] = $this->byName($value);
        }
        return $fields;
    }
    public function fillFields($array)
    {
        foreach ($array as $key => $value) {
            $this->byName($key)->clear();
Esempio n. 5
0
 /**
  * Test whether we can create an instant database using
  * R::setup().
  *
  * Probably only works on *NIX systems.
  *
  * @return void
  */
 public function testSetup()
 {
     $tmpDir = sys_get_temp_dir();
     R::setup();
 }
Esempio n. 6
0
<?php

//inlcude of Slim Framework and RedBeanPHP
require 'vendor/autoload.php';
/* Declare RedBeanPHP
 * RedBean version : 4.2.1
 */
use RedBeanPHP\Facade as R;
//Declare Slim
$app = new \Slim\Slim();
//Connection at the database by RedBeanPHP
R::setup('mysql:host=localhost;dbname=GoBus_v3.0', 'root', 'pwsio');
//Route
//Return line by name city departure
$app->get('/line/:cityName', function ($cityName) {
    $city = R::exportAll(R::find('city', 'WHERE name="' . $cityName . '"'));
    $lines = R::exportAll(R::find('line', 'WHERE start_point_id=' . $city[0]['id']));
    echo json_encode($lines);
});
//Return departure time and end_point_id
$app->get('/timetable/:cityName/:day', function ($cityName, $day) {
    $city = R::exportAll(R::find('city', 'WHERE name="' . $cityName . '"'));
    $lines = R::exportAll(R::find('line', 'WHERE start_point_id=' . $city[0]['id']));
    $timetableCityDay = array();
    foreach ($lines as $line) {
        $timetable = R::exportAll(R::find('timetable', 'WHERE line_id=' . $line['id'] . ' AND day=' . $day));
        var_dump($timetable);
        if (!empty($timetable)) {
            $timetableCityDay[] = array($timetable[0]['start_time'], $line['end_point_id']);
        }
    }
Esempio n. 7
0
/*Include constants
* @TODO Rename the DATA_.php file in DATA.php.
* @TODO Put some content on the constant to connect at database
*/
include '__param/DATA.php';
session_start();
//Declare Slim Framework
$app = new \Slim\Slim(array('templates.path' => 'css/template'));
//Declare RedBeanPHP
use RedBeanPHP\Facade as R;
/*Prepare Connexion
* @TODO edit $connect : $connect=new Connection("host","dbname","user","password");
*/
$connect = new Connection();
//Connection at the database
R::setup('mysql:host=' . $connect->getHost() . ';dbname=' . $connect->getDbname() . '', $connect->getUser(), $connect->getPassword());
//Add the template header
$app->render('head.php');
//Route
$app->get('/', function () use($app) {
    include 'core_mod/people.php';
    $user = R::findAll('user');
});
$app->get('/:mod', function ($mod) use($app) {
    $file = '/__mod/' . $mod . '/index.php';
    if (file_exists($file)) {
        include $file;
        /*
         *	Rank authorisation
         */
    } else {
Esempio n. 8
0
<?php

require_once __DIR__ . '/config.inc.php';
require_once __DIR__ . '/../vendor/autoload.php';
use RedBeanPHP\Facade as R;
if (empty(R::$currentDB)) {
    $dsn = sprintf('%s:host=%s;dbname=%s', DB_TYPE, DB_HOST, DB_NAME);
    R::setup($dsn, DB_USER, DB_PASSWORD);
}
R::close();
Esempio n. 9
0
 public static function ConfigSetup($arrconfig = null)
 {
     if (is_array($arrconfig) && !empty($arrconfig)) {
         if ($arrconfig['server']) {
             self::$server = $arrconfig['server'];
         }
         if ($arrconfig['databasename']) {
             self::$databasename = $arrconfig['databasename'];
         }
         if ($arrconfig['username']) {
             self::$username = $arrconfig['username'];
         }
         if ($arrconfig['password']) {
             self::$password = $arrconfig['password'];
         }
         if ($arrconfig['port']) {
             self::$port = $arrconfig['port'];
         }
     }
     self::$connection = new PDO('mysql:host=' . self::$server . ';port=' . self::$port . ';dbname=' . self::$databasename . ';', self::$username, self::$password);
     self::$connection->query('SET NAMES utf8');
     R::setup(self::$connection);
     R::freeze(true);
     self::$logsrv = new \RedBeanPHP\Plugin\SystemlogsService();
     R::debug(true, 1);
 }
Esempio n. 10
0
<?php

require 'vendor/autoload.php';
use RedBeanPHP\Facade as R;
$app = new \Slim\Slim();
$app->get('/line/:numLine', function ($numLine) {
    R::setup('mysql:host=localhost;  
        dbname=db_goBus', 'root', 'pwsio');
    $row = R::findAll('line', ' where id=' . $numLine);
    //display data line entered into id   'name table', 'condition sup'
    $exportRow = R::exportAll($row);
    echo json_encode($exportRow);
    //js_encode serve to display data all in the inpu line on url
});
$app->run();
Esempio n. 11
0
 /**
  * @param string $dsn
  * @param $user
  * @param string $password
  * @param bool $isDevMode
  */
 public static function setupRedBean($dsn, $user, $password = '', $isDevMode = false)
 {
     $toolbox = R::getToolBox();
     if (empty($toolbox)) {
         R::setup($dsn, $user, $password, !$isDevMode);
     }
 }
Esempio n. 12
0
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/
require __DIR__ . '/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Include The Compiled Class File
|--------------------------------------------------------------------------
|
| To dramatically increase your application's performance, you may use a
| compiled class file which contains all of the classes commonly used
| by a request. The Artisan "optimize" is used to create this file.
|
*/
$compiledPath = __DIR__ . '/cache/compiled.php';
if (file_exists($compiledPath)) {
    require $compiledPath;
}
/**
 * Ruslan K
 */
use RedBeanPHP\Facade as R;
R::setup('sqlite:../dbfile.sq3');