Database PHP Class Code Examples

This page contains top rated real world PHP examples of class Database extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: PropelTableForeignKeyComparatorTest.php Project: disider/Propel2
0
 public function testCompareModifiedFks()
 {
     $db1 = new Database();
     $db1->setPlatform($this->platform);
     $c1 = new Column('Foo');
     $c2 = new Column('Bar');
     $fk1 = new ForeignKey('my_foreign_key');
     $fk1->addReference($c1, $c2);
     $t1 = new Table('Baz');
     $t1->addForeignKey($fk1);
     $db1->addTable($t1);
     $db2 = new Database();
     $db2->setPlatform($this->platform);
     $c3 = new Column('Foo');
     $c4 = new Column('Bar2');
     $fk2 = new ForeignKey('my_foreign_key');
     $fk2->addReference($c3, $c4);
     $t2 = new Table('Baz');
     $t2->addForeignKey($fk2);
     $db2->addTable($t2);
     $tc = new TableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareForeignKeys();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(1, $nbDiffs);
     $this->assertEquals(1, count($tableDiff->getModifiedFks()));
     $this->assertEquals(['my_foreign_key' => [$fk1, $fk2]], $tableDiff->getModifiedFks());
 }
Example #2
Show file File: PropelDataDumpTask.php Project: DBezemer/server
0
 /**
  * Creates a DOM document containing data for specified database.
  * @param Database $database
  * @return DOMDocument
  */
 private function createXMLDoc(Database $database)
 {
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     // pretty printing
     $doc->appendChild($doc->createComment("Created by data/dump/Control.tpl template."));
     $dsNode = $doc->createElement("dataset");
     $dsNode->setAttribute("name", "all");
     $doc->appendChild($dsNode);
     $this->log("Building DOM tree containing data from tables:");
     foreach ($database->getTables() as $tbl) {
         $this->log("\t+ " . $tbl->getName());
         $rs = $this->getTableDataRS($tbl->getName());
         while ($rs->next()) {
             $rowNode = $doc->createElement($tbl->getPhpName());
             foreach ($tbl->getColumns() as $col) {
                 $cval = $rs->get($col->getName());
                 if ($cval !== null) {
                     $rowNode->setAttribute($col->getPhpName(), iconv($this->dbEncoding, 'utf-8', $cval));
                 }
             }
             $dsNode->appendChild($rowNode);
             unset($rowNode);
         }
         $rs->close();
     }
     return $doc;
 }
Example #3
Show file File: PgsqlSchemaParser.php Project: RadioCampusFrance/airtime
0
 /**
  * Adds the sequences for this database.
  *
  * @return     void
  * @throws     SQLException
  */
 protected function addSequences(Database $database)
 {
     /*
     -- WE DON'T HAVE ANY USE FOR THESE YET IN REVERSE ENGINEERING ...
     $this->sequences = array();
     $result = pg_query($this->conn->getResource(), "SELECT c.oid,
     						                        case when n.nspname='public' then c.relname else n.nspname||'.'||c.relname end as relname
     						                        FROM pg_class c join pg_namespace n on (c.relnamespace=n.oid)
     						                        WHERE c.relkind = 'S'
     						                          AND n.nspname NOT IN ('information_schema','pg_catalog')
     						                          AND n.nspname NOT LIKE 'pg_temp%'
     						                          AND n.nspname NOT LIKE 'pg_toast%'
     						                        ORDER BY relname");
     
     if (!$result) {
     	throw new SQLException("Could not list sequences", pg_last_error($this->dblink));
     }
     
     while ($row = pg_fetch_assoc($result)) {
     	// FIXME -- decide what info we need for sequences & then create a SequenceInfo object (if needed)
     	$obj = new stdClass;
     	$obj->name = $row['relname'];
     	$obj->oid = $row['oid'];
     	$this->sequences[strtoupper($row['relname'])] = $obj;
     }
     */
 }
Example #4
Show file File: Voluntario.php Project: lealheda/Itcvolbank
0
 public function getOrganizacion()
 {
     $coneccion = new Database();
     $id = $_SESSION['usuario']['id'];
     $obj = $coneccion->query("SELECT usu.*,IFNULL(nombre, '') AS nombre, IFNULL(calle, '') AS calle, IFNULL(numero, 0) AS numero, IFNULL(colonia, 0) AS colonia,\n                    IFNULL(codigo_postal, 0) AS codigo_postal, IFNULL(ciudad, '') AS ciudad, IFNULL(pais,'') AS pais, IFNULL(telefono, '') AS telefono,\n                    IFNULL(descripcion, '') AS descripcion, IFNULL(estado, '') AS estado\n                    FROM usuario usu\n                    LEFT JOIN organizacion org ON org.id_usuario = usu.id\n                    WHERE usu.id={$id}");
     $result = $obj->fetch_object();
     if (is_object($result)) {
         return $result;
     } else {
         $temp = new stdClass();
         $temp->nombre = "";
         $temp->descripcion = "";
         $temp->calle = "";
         $temp->numero = "";
         $temp->colonia = "";
         $temp->codigo_postal = "";
         $temp->ciudad = "";
         $temp->pais = "";
         $temp->telefono = "";
         $temp->estado = "";
         $temp->correo_electronico = "";
         $temp->contrasena = "";
         return $temp;
     }
 }
Example #5
Show file File: MysqlSchemaParser.php Project: yasirgit/afids
0
 /**
  *
  */
 public function parse(Database $database)
 {
     $this->addVendorInfo = $this->getGeneratorConfig()->getBuildProperty('addVendorInfo');
     $stmt = $this->dbh->query("SHOW TABLES");
     // First load the tables (important that this happen before filling out details of tables)
     $tables = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $name = $row[0];
         $table = new Table($name);
         $database->addTable($table);
         $tables[] = $table;
     }
     // Now populate only columns.
     foreach ($tables as $table) {
         $this->addColumns($table);
     }
     // Now add indexes and constraints.
     foreach ($tables as $table) {
         $this->addForeignKeys($table);
         $this->addIndexes($table);
         $this->addPrimaryKey($table);
         if ($this->addVendorInfo) {
             $this->addTableVendorInfo($table);
         }
     }
 }
Example #6
Show file File: ConfigController.php Project: billyprice1/phpservermon
0
 function __construct(Database $db, \Twig_Environment $twig)
 {
     parent::__construct($db, $twig);
     $this->setMinUserLevelRequired(PSM_USER_ADMIN);
     $this->setCSRFKey('config');
     $this->setActions(array('index', 'save'), 'index');
 }
Example #7
Show file File: ListAssociation.php Project: ablyler/phan
0
 /**
  * @param Database $database
  * The database to read from
  *
  * @param string|array $pirmary_key_value
  * The PKID of the the row to delete
  */
 public function delete(Database $database, $primary_key_value)
 {
     // Ensure that we've initialized this model
     $this->schema->initializeOnce($database);
     $query = $this->schema->queryForDeleteColumnValue('source_pk', $primary_key_value);
     $database->exec($query);
 }
Example #8
Show file File: ReverseManager.php Project: disider/Propel2
0
 /**
  * Builds the model classes from the database schema.
  *
  * @return Database The built-out Database (with all tables, etc.)
  */
 protected function buildModel()
 {
     $config = $this->getGeneratorConfig();
     $connection = $this->getConnection();
     $databaseName = $config->getConfigProperty('reverse.connection');
     $database = new Database($this->getDatabaseName());
     $database->setPlatform($config->getConfiguredPlatform($connection), $databaseName);
     $database->setDefaultIdMethod(IdMethod::NATIVE);
     $buildConnection = $config->getBuildConnection($databaseName);
     $this->log(sprintf('Reading database structure of database `%s` using dsn `%s`', $this->getDatabaseName(), $buildConnection['dsn']));
     $parser = $config->getConfiguredSchemaParser($connection, $databaseName);
     $this->log(sprintf('SchemaParser `%s` chosen', get_class($parser)));
     $nbTables = $parser->parse($database);
     $excludeTables = $config->getConfigProperty('exclude_tables');
     $tables = [];
     foreach ($database->getTables() as $table) {
         /* Was copypasted from DatabaseComparator::isTableExcluded() */
         $skip = false;
         $tablename = $table->getName();
         if (in_array($tablename, $excludeTables)) {
             $skip = true;
         } else {
             foreach ($excludeTables as $exclude_tablename) {
                 if (preg_match('/^' . str_replace('*', '.*', $exclude_tablename) . '$/', $tablename)) {
                     $skip = true;
                 }
             }
         }
         $skip && $database->removeTable($table);
     }
     $this->log(sprintf('Successfully reverse engineered %d tables', $nbTables));
     return $database;
 }
Example #9
Show file File: MssqlSchemaParser.php Project: kalaspuffar/php-orm-benchmark
0
 /**
  *
  */
 public function parse(Database $database, Task $task = null)
 {
     $stmt = $this->dbh->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'");
     // First load the tables (important that this happen before filling out details of tables)
     $tables = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $name = $this->cleanDelimitedIdentifiers($row[0]);
         if ($name == $this->getMigrationTable()) {
             continue;
         }
         $table = new Table($name);
         $table->setIdMethod($database->getDefaultIdMethod());
         $database->addTable($table);
         $tables[] = $table;
     }
     // Now populate only columns.
     foreach ($tables as $table) {
         $this->addColumns($table);
     }
     // Now add indexes and constraints.
     foreach ($tables as $table) {
         $this->addForeignKeys($table);
         $this->addIndexes($table);
         $this->addPrimaryKey($table);
     }
     return count($tables);
 }
Example #10
Show file File: PropelDataDumpTask.php Project: dracony/forked-php-orm-benchmark
0
 /**
  * Creates a DOM document containing data for specified database.
  *
  * @param Database $database
  *
  * @return DOMDocument
  */
 private function createXMLDoc(Database $database)
 {
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     // pretty printing
     $doc->appendChild($doc->createComment("Created by PropelDataDumpTask."));
     $dsNode = $doc->createElement("dataset");
     $dsNode->setAttribute("name", "all");
     $doc->appendChild($dsNode);
     $platform = $this->getGeneratorConfig()->getConfiguredPlatform($this->conn);
     $this->log("Building DOM tree containing data from tables:");
     foreach ($database->getTables() as $tbl) {
         $this->log("\t+ " . $tbl->getName());
         $stmt = $this->getTableDataStmt($tbl->getName(), $platform);
         while ($row = $stmt->fetch()) {
             $rowNode = $doc->createElement($tbl->getPhpName());
             foreach ($tbl->getColumns() as $col) {
                 $cval = $row[$col->getName()];
                 if ($cval !== null) {
                     $rowNode->setAttribute($col->getPhpName(), iconv($this->dbEncoding, 'utf-8', $cval));
                 }
             }
             $dsNode->appendChild($rowNode);
             unset($rowNode);
         }
         unset($stmt);
     }
     return $doc;
 }
Example #11
Show file File: PropelTableForeignKeyComparatorTest.php Project: kalaspuffar/php-orm-benchmark
0
 public function testCompareModifiedFks()
 {
     $db1 = new Database();
     $db1->setPlatform($this->platform);
     $c1 = new Column('Foo');
     $c2 = new Column('Bar');
     $fk1 = new ForeignKey();
     $fk1->addReference($c1, $c2);
     $t1 = new Table('Baz');
     $t1->addForeignKey($fk1);
     $db1->addTable($t1);
     $t1->doNaming();
     $db2 = new Database();
     $db2->setPlatform($this->platform);
     $c3 = new Column('Foo');
     $c4 = new Column('Bar2');
     $fk2 = new ForeignKey();
     $fk2->addReference($c3, $c4);
     $t2 = new Table('Baz');
     $t2->addForeignKey($fk2);
     $db2->addTable($t2);
     $t2->doNaming();
     $tc = new TableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareForeignKeys();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(1, $nbDiffs);
     $this->assertEquals(1, count($tableDiff->getModifiedFks()));
     $this->assertEquals(array('Baz_FK_1' => array($fk1, $fk2)), $tableDiff->getModifiedFks());
 }
Example #12
Show file File: model_reto.php Project: developergate/ET1v2
0
 public function eliminar($pk)
 {
     $db = new Database();
     $result = $db->consulta('DELETE FROM Reto WHERE idReto = \'' . $pk . '\'') or die('Error al eliminar el reto');
     $db->desconectar();
     return result;
 }
Example #13
Show file File: insert.php Project: gilyaev/framework-bench
0
 /**
  * Compile the SQL query and return it.
  *
  * @param   object  Database instance
  * @return  string
  */
 public function compile(Database $db)
 {
     // Start an insertion query
     $query = 'INSERT INTO ' . $db->quote_table($this->_table);
     // Add the column names
     $query .= ' (' . implode(', ', array_map(array($db, 'quote_column'), $this->_columns)) . ') ';
     if (is_array($this->_values)) {
         // Callback for quoting values
         $quote = array($db, 'quote');
         $groups = array();
         foreach ($this->_values as $group) {
             foreach ($group as $offset => $value) {
                 if ((is_string($value) and array_key_exists($value, $this->_parameters)) === FALSE) {
                     // Quote the value, it is not a parameter
                     $group[$offset] = $db->quote($value);
                 }
             }
             $groups[] = '(' . implode(', ', $group) . ')';
         }
         // Add the values
         $query .= 'VALUES ' . implode(', ', $groups);
     } else {
         // Add the sub-query
         $query .= (string) $this->_values;
     }
     $this->_sql = $query;
     return parent::compile($db);
 }
Example #14
Show file File: CollectionTest.php Project: letrunghieu/mongodb
0
 private function getTestCollection(Database $db = null, MongoCollection $mc = null, EventManager $em = null)
 {
     $db = $db ?: $this->getMockDatabase();
     $mc = $mc ?: $this->getMockMongoCollection();
     $em = $em ?: $this->getMockEventManager();
     return new Collection($db, $mc, $em);
 }
Example #15
Show file File: LoginController.php Project: billyprice1/phpservermon
0
 function __construct(Database $db, \Twig_Environment $twig)
 {
     parent::__construct($db, $twig);
     $this->setMinUserLevelRequired(PSM_USER_ANONYMOUS);
     $this->setActions(array('login', 'forgot', 'reset'), 'login');
     $this->addMenu(false);
 }
Example #16
Show file File: GetBook.php Project: loi219/Shared-library
0
 function getBooksByIdUser($idUser, $idBook)
 {
     $db = new Database();
     $query = "SELECT * FROM books b LEFT JOIN users u  ON b.fk_owner = u.user_id WHERE b.id_book ='{$idBook}' AND b.fk_user='{$idUser}'";
     $arrayBooks = $db->select($query);
     return $this->arrayBooks = $arrayBooks;
 }
Example #17
Show file File: PropelDatabaseTableComparatorTest.php Project: kalaspuffar/php-orm-benchmark
0
 public function testCompareSeveralTableDifferences()
 {
     $d1 = new Database();
     $t1 = new Table('Foo_Table');
     $c1 = new Column('Foo');
     $c1->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c1->getDomain()->replaceScale(2);
     $c1->getDomain()->replaceSize(3);
     $c1->setNotNull(true);
     $c1->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t1->addColumn($c1);
     $d1->addTable($t1);
     $t2 = new Table('Bar');
     $c2 = new Column('Bar_Column');
     $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $t2->addColumn($c2);
     $d1->addTable($t2);
     $t11 = new Table('Baz');
     $d1->addTable($t11);
     $d2 = new Database();
     $t3 = new Table('Foo_Table');
     $c3 = new Column('Foo1');
     $c3->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c3->getDomain()->replaceScale(2);
     $c3->getDomain()->replaceSize(3);
     $c3->setNotNull(true);
     $c3->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t3->addColumn($c3);
     $d2->addTable($t3);
     $t4 = new Table('Bar2');
     $c4 = new Column('Bar_Column');
     $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $t4->addColumn($c4);
     $d2->addTable($t4);
     $t5 = new Table('Biz');
     $c5 = new Column('Biz_Column');
     $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $t5->addColumn($c5);
     $d2->addTable($t5);
     // Foo_Table was modified, Bar was renamed, Baz was removed, Biz was added
     $dc = new PropelDatabaseComparator();
     $dc->setFromDatabase($d1);
     $dc->setToDatabase($d2);
     $nbDiffs = $dc->compareTables();
     $databaseDiff = $dc->getDatabaseDiff();
     $this->assertEquals(4, $nbDiffs);
     $this->assertEquals(array('Bar' => 'Bar2'), $databaseDiff->getRenamedTables());
     $this->assertEquals(array('Biz' => $t5), $databaseDiff->getAddedTables());
     $this->assertEquals(array('Baz' => $t11), $databaseDiff->getRemovedTables());
     $tableDiff = PropelTableComparator::computeDiff($t1, $t3);
     $this->assertEquals(array('Foo_Table' => $tableDiff), $databaseDiff->getModifiedTables());
 }
Example #18
Show file File: PropelDatabaseComparator.php Project: kalaspuffar/php-orm-benchmark
0
 /**
  * Compute and return the difference between two database objects
  *
  * @param Database $fromDatabase
  * @param Database $toDatabase
  * @param boolean  $caseInsensitive Whether the comparison is case insensitive.
  *                                  False by default.
  *
  * @return PropelDatabaseDiff|boolean return false if the two databases are similar
  */
 public static function computeDiff(Database $fromDatabase, Database $toDatabase, $caseInsensitive = false)
 {
     $dc = new self();
     $dc->setFromDatabase($fromDatabase);
     $dc->setToDatabase($toDatabase);
     $differences = 0;
     $differences += $dc->compareTables($caseInsensitive);
     return $differences > 0 ? $dc->getDatabaseDiff() : false;
 }
Example #19
Show file File: PropelSQLTask.php Project: DBezemer/server
0
 protected function cloneDatabase($db)
 {
     $attributes = array('name' => $db->getName(), 'baseClass' => $db->getBaseClass(), 'basePeer' => $db->getBasePeer(), 'defaultIdMethod' => $db->getDefaultIdMethod(), 'defaultPhpNamingMethod' => $db->getDefaultPhpNamingMethod(), 'defaultTranslateMethod' => $db->getDefaultTranslateMethod());
     $clone = new Database();
     $clone->loadFromXML($attributes);
     return $clone;
 }
Frequently Used Methods