Пример #1
0
 /**
  * Initializes the database and prepares a toolbox.
  * The kickstart method assembles a toolbox based on your DSN and
  * credentials and returns it.
  * The toolbox contains all the necessary core components for
  * RedBeanPHP to start working with your database. Most RedBeanPHP
  * components are stand-alone and require a toolbox to work.
  *
  * @param  string|PDO $dsn      Database Connection String (or PDO instance)
  * @param  string     $username Username for database
  * @param  string     $password Password for database
  * @param  boolean    $frozen   Start in frozen mode?
  *
  * @return RedBean_ToolBox
  */
 public static function kickstart($dsn, $username = NULL, $password = NULL, $frozen = FALSE, $autoSetEncoding = TRUE)
 {
     if ($dsn instanceof PDO) {
         $db = new RedBean_Driver_PDO($dsn);
         $dsn = $db->getDatabaseType();
     } else {
         self::checkDSN($dsn);
         if (strpos($dsn, 'oracle') === 0) {
             $db = new RedBean_Driver_OCI($dsn, $username, $password);
         } else {
             $db = new RedBean_Driver_PDO($dsn, $username, $password, $autoSetEncoding);
         }
     }
     $adapter = new RedBean_Adapter_DBAdapter($db);
     if (strpos($dsn, 'pgsql') === 0) {
         $writer = new RedBean_QueryWriter_PostgreSQL($adapter);
     } else {
         if (strpos($dsn, 'sqlite') === 0) {
             $writer = new RedBean_QueryWriter_SQLiteT($adapter);
         } else {
             if (strpos($dsn, 'cubrid') === 0) {
                 $writer = new RedBean_QueryWriter_CUBRID($adapter);
             } else {
                 if (strpos($dsn, 'oracle') === 0) {
                     $writer = new RedBean_QueryWriter_Oracle($adapter);
                 } else {
                     $writer = new RedBean_QueryWriter_MySQL($adapter);
                 }
             }
         }
     }
     $redbean = new RedBean_OODB($writer);
     if ($frozen) {
         $redbean->freeze(TRUE);
     }
     $toolbox = new RedBean_ToolBox($redbean, $adapter, $writer);
     return $toolbox;
 }
Пример #2
0
 /**
  * Toggles fluid or frozen mode. In fluid mode the database
  * structure is adjusted to accomodate your objects. In frozen mode
  * this is not the case.
  *
  * You can also pass an array containing a selection of frozen types.
  * Let's call this chilly mode, it's just like fluid mode except that
  * certain types (i.e. tables) aren't touched.
  *
  * @param boolean|array $trueFalse
  */
 public static function freeze($tf = true)
 {
     self::$redbean->freeze($tf);
 }
Пример #3
0
 public static function kickstart($dsn, $username = NULL, $password = NULL, $frozen = false)
 {
     if ($dsn instanceof PDO) {
         $pdo = new RedBean_Driver_PDO($dsn);
         $dsn = $pdo->getDatabaseType();
     } else {
         self::checkDSN($dsn);
         $pdo = new RedBean_Driver_PDO($dsn, $username, $password);
     }
     $adapter = new RedBean_Adapter_DBAdapter($pdo);
     if (strpos($dsn, "pgsql") === 0) {
         $writer = new RedBean_QueryWriter_PostgreSQL($adapter);
     } else {
         if (strpos($dsn, "sqlite") === 0) {
             $writer = new RedBean_QueryWriter_SQLiteT($adapter);
         } else {
             $writer = new RedBean_QueryWriter_MySQL($adapter);
         }
     }
     $redbean = new RedBean_OODB($writer);
     if ($frozen) {
         $redbean->freeze(true);
     }
     $toolbox = new RedBean_ToolBox($redbean, $adapter, $writer);
     self::$toolbox = $toolbox;
     return self::$toolbox;
 }
 /**
  * Toggles fluid or frozen mode. In fluid mode the database
  * structure is adjusted to accomodate your objects. In frozen mode
  * this is not the case.
  *
  * You can also pass an array containing a selection of frozen types.
  * Let's call this chilly mode, it's just like fluid mode except that
  * certain types (i.e. tables) aren't touched.
  *
  * @param boolean|array $trueFalse
  */
 public function freeze($tf = TRUE)
 {
     $this->redbean->freeze($tf);
 }
Пример #5
0
$nullWriter->returnScanType = 777;
$nullWriter->returnTables = array("bean");
$nullWriter->returnGetColumns = array("name" => 13);
asrt($redbean->store($bean), 9876);
asrt($nullWriter->getColumnsArgument, "bean");
asrt($nullWriter->createTableArgument, NULL);
asrt($nullWriter->scanTypeArgument, "chili");
asrt($nullWriter->codeArgument, 13);
asrt($nullWriter->addColumnArguments, array());
asrt($nullWriter->insertRecordArguments, array());
asrt($nullWriter->addUniqueIndexArguments, array());
asrt($nullWriter->updateRecordArguments, array("bean", array(array("property" => "name", "value" => "chili")), 9876));
asrt($nullWriter->widenColumnArguments, array("bean", "name", 777));
testpack("UNIT TEST RedBean OODB: Freeze");
$nullWriter->reset();
$redbean->freeze(true);
$bean = $redbean->dispense("bean");
$bean->name = "coffee";
$nullWriter->returnScanType = 91239;
$nullWriter->returnInsertRecord = 1234;
asrt($redbean->store($bean), 1234);
asrt($nullWriter->getColumnsArgument, "bean");
asrt($nullWriter->createTableArgument, NULL);
asrt($nullWriter->scanTypeArgument, NULL);
asrt($nullWriter->codeArgument, NULL);
asrt($nullWriter->addColumnArguments, array());
asrt($nullWriter->insertRecordArguments, array("bean", array("name"), array(array("coffee"))));
asrt($nullWriter->addUniqueIndexArguments, array());
asrt($nullWriter->updateRecordArguments, array());
asrt($nullWriter->widenColumnArguments, array());
$redbean->freeze(false);
Пример #6
0
    $db->setDebugMode(1);
}
RedBean_OODB::$db = new RedBean_DBAdapter($db);
//Wrap ADO in RedBean's adapter
if ($engine) {
    RedBean_OODB::setEngine($engine);
    //select a database driver
}
RedBean_OODB::init();
//Init RedBean
if ($unlockall) {
    RedBean_OODB::resetAll();
    //Release all locks
}
if ($freeze) {
    RedBean_OODB::freeze();
    //Decide whether to freeze the database
}
//Define some handy exceptions
//Exception for locking mechanism
class ExceptionFailedAccessBean extends Exception
{
}
//Exception for invalid parent-child associations (type mismatch)
class ExceptionInvalidParentChildCombination extends Exception
{
}
//Exception for invalid search operators
class ExceptionInvalidFindOperator extends Exception
{
}
Пример #7
0
 /**
  * Kickstarts RedBean :)
  * @param $dsn
  * @param $username
  * @param $password
  * @param $freeze
  * @param $engine
  * @param $debugmode
  * @param $unlockall
  * @return unknown_type
  */
 public static function kickstart($dsn = "mysql:host=localhost;dbname=oodb", $username = '******', $password = '', $freeze = false, $engine = "innodb", $debugmode = false, $unlockall = false)
 {
     //This is no longer configurable
     eval("\n\t\t\tclass R extends RedBean_OODB { }\n\t\t");
     eval("\n\t\t\tclass RD extends RedBean_Decorator { }\n\t\t");
     //get an instance of the MySQL database
     $db = PDODriver::getInstance($dsn, $username, $password, null);
     if ($debugmode) {
         $db->setDebugMode(1);
     }
     RedBean_OODB::$db = new RedBean_DBAdapter($db);
     //Wrap ADO in RedBean's adapter
     RedBean_OODB::setEngine($engine);
     //select a database driver
     RedBean_OODB::init();
     //Init RedBean
     if ($unlockall) {
         RedBean_OODB::resetAll();
         //Release all locks
     }
     if ($freeze) {
         RedBean_OODB::freeze();
         //Decide whether to freeze the database
     }
 }