diff --git a/MDB_test.php b/MDB_test.php index ca1ebfc..a9afaa3 100644 --- a/MDB_test.php +++ b/MDB_test.php @@ -23,32 +23,20 @@ } echo $db_type.'
'; - if($db_type == 'mysql') { - // just for kicks you can mess up this part to see some pear error handling - $dsn['username'] = $user; - $dsn['password'] = $pass; - //$pass = ''; - $dsn['hostspec'] = $host; - // Data Source Name: This is the universal connection string - $dsn['phptype'] = $db_type; - - $manager = new MDB_manager; - $input_file = 'metapear_test_db.schema'; - $manager->connect($dsn); - // lets create the database using 'metapear_test_db.schema' - // if you have allready run this script you should have 'metapear_test_db.schema.before' - // in that case MDB will just compare the two schemas and make any necessary modifications to the existing DB - echo Var_Dump::display($manager->updateDatabase($input_file, $input_file.'.before')).'
'; - echo 'updating database from xml schema file
'; - } // Data Source Name: This is the universal connection string - $dsn = "$db_type://$user:$pass@$host/$db_name"; + $dsn['username'] = $user; + $dsn['password'] = $pass; + $dsn['hostspec'] = $host; + $dsn['database'] = $db_name; + $dsn['phptype'] = $db_type; // MDB::connect will return a Pear DB object on success // or a Pear DB Error object on error // You can also set to TRUE the second param // if you want a persistent connection: // $db = MDB::connect($dsn, TRUE); + // you can alternatively build a dsn here + //$dsn = "$db_type://$user:$pass@$host/$db_name"; $db = MDB::connect($dsn); // With MDB::isError you can differentiate between an error or // a valid connection. @@ -56,6 +44,18 @@ die ($db->getMessage()); } + if($db_type == 'mysql') { + $manager = new MDB_manager; + $input_file = 'metapear_test_db.schema'; + // you can either pass a dsn string, a dsn array or an exisiting db connection + $manager->connect($db); + // lets create the database using 'metapear_test_db.schema' + // if you have allready run this script you should have 'metapear_test_db.schema.before' + // in that case MDB will just compare the two schemas and make any necessary modifications to the existing DB + echo Var_Dump::display($manager->updateDatabase($input_file, $input_file.'.before')).'
'; + echo 'updating database from xml schema file
'; + } + // happy query $query ='SELECT * FROM test'; echo 'query for the following examples:'.$query.'
'; @@ -138,7 +138,6 @@ $array = array(4); echo '
see getOne in action:
'; echo Var_Dump::display($db->getOne('SELECT trans_en FROM numbers WHERE number = ?','text',$array)).'
'; - // You can disconnect from the database with: echo '
see getRow in action:
'; echo Var_Dump::display($db->getRow('SELECT * FROM numbers WHERE number = ?',array('integer','text','text'),$array)).'
'; echo '
see getCol in action:
'; @@ -178,20 +177,19 @@ // this feature is especially interesting for people that have an existing Db and want to move to MDB's xml schema management echo Var_Dump::display($manager->dumpDatabase( array( - 'Output' => 'Dump', - 'EndOfLine' => "\n", 'Output_Mode' => 'file', - 'Output_File' => $db_name.'2.schema' + 'Output' => $db_name.'2.schema' ), MDB_MANAGER_DUMP_STRUCTURE )).'
'; if($manager->database) { echo Var_Dump::display($manager->database->debugOutput()).'
'; } - // this is the database definition as an array echo Var_Dump::display($manager->database_definition).'
'; } echo '
just a simple delete query:
'; echo Var_Dump::display($db->query('DELETE FROM numbers')).'
'; + // You can disconnect from the database with: + $db->disconnect() ?> diff --git a/tests/MDB_test.php b/tests/MDB_test.php index ca1ebfc..a9afaa3 100644 --- a/tests/MDB_test.php +++ b/tests/MDB_test.php @@ -23,32 +23,20 @@ } echo $db_type.'
'; - if($db_type == 'mysql') { - // just for kicks you can mess up this part to see some pear error handling - $dsn['username'] = $user; - $dsn['password'] = $pass; - //$pass = ''; - $dsn['hostspec'] = $host; - // Data Source Name: This is the universal connection string - $dsn['phptype'] = $db_type; - - $manager = new MDB_manager; - $input_file = 'metapear_test_db.schema'; - $manager->connect($dsn); - // lets create the database using 'metapear_test_db.schema' - // if you have allready run this script you should have 'metapear_test_db.schema.before' - // in that case MDB will just compare the two schemas and make any necessary modifications to the existing DB - echo Var_Dump::display($manager->updateDatabase($input_file, $input_file.'.before')).'
'; - echo 'updating database from xml schema file
'; - } // Data Source Name: This is the universal connection string - $dsn = "$db_type://$user:$pass@$host/$db_name"; + $dsn['username'] = $user; + $dsn['password'] = $pass; + $dsn['hostspec'] = $host; + $dsn['database'] = $db_name; + $dsn['phptype'] = $db_type; // MDB::connect will return a Pear DB object on success // or a Pear DB Error object on error // You can also set to TRUE the second param // if you want a persistent connection: // $db = MDB::connect($dsn, TRUE); + // you can alternatively build a dsn here + //$dsn = "$db_type://$user:$pass@$host/$db_name"; $db = MDB::connect($dsn); // With MDB::isError you can differentiate between an error or // a valid connection. @@ -56,6 +44,18 @@ die ($db->getMessage()); } + if($db_type == 'mysql') { + $manager = new MDB_manager; + $input_file = 'metapear_test_db.schema'; + // you can either pass a dsn string, a dsn array or an exisiting db connection + $manager->connect($db); + // lets create the database using 'metapear_test_db.schema' + // if you have allready run this script you should have 'metapear_test_db.schema.before' + // in that case MDB will just compare the two schemas and make any necessary modifications to the existing DB + echo Var_Dump::display($manager->updateDatabase($input_file, $input_file.'.before')).'
'; + echo 'updating database from xml schema file
'; + } + // happy query $query ='SELECT * FROM test'; echo 'query for the following examples:'.$query.'
'; @@ -138,7 +138,6 @@ $array = array(4); echo '
see getOne in action:
'; echo Var_Dump::display($db->getOne('SELECT trans_en FROM numbers WHERE number = ?','text',$array)).'
'; - // You can disconnect from the database with: echo '
see getRow in action:
'; echo Var_Dump::display($db->getRow('SELECT * FROM numbers WHERE number = ?',array('integer','text','text'),$array)).'
'; echo '
see getCol in action:
'; @@ -178,20 +177,19 @@ // this feature is especially interesting for people that have an existing Db and want to move to MDB's xml schema management echo Var_Dump::display($manager->dumpDatabase( array( - 'Output' => 'Dump', - 'EndOfLine' => "\n", 'Output_Mode' => 'file', - 'Output_File' => $db_name.'2.schema' + 'Output' => $db_name.'2.schema' ), MDB_MANAGER_DUMP_STRUCTURE )).'
'; if($manager->database) { echo Var_Dump::display($manager->database->debugOutput()).'
'; } - // this is the database definition as an array echo Var_Dump::display($manager->database_definition).'
'; } echo '
just a simple delete query:
'; echo Var_Dump::display($db->query('DELETE FROM numbers')).'
'; + // You can disconnect from the database with: + $db->disconnect() ?>