Skip to content

Commit

Permalink
some more API updates to the manager tests
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/MDB/trunk@90521 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Lukas Smith committed Jul 31, 2002
1 parent 8c95f56 commit 849ee65
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 48 deletions.
46 changes: 22 additions & 24 deletions MDB_test.php
Expand Up @@ -23,39 +23,39 @@
}
echo $db_type.'<br>';

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')).'<br>';
echo 'updating database from xml schema file<br>';
}

// 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.
if (MDB::isError($db)) {
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')).'<br>';
echo 'updating database from xml schema file<br>';
}

// happy query
$query ='SELECT * FROM test';
echo 'query for the following examples:'.$query.'<br>';
Expand Down Expand Up @@ -138,7 +138,6 @@
$array = array(4);
echo '<br>see getOne in action:<br>';
echo Var_Dump::display($db->getOne('SELECT trans_en FROM numbers WHERE number = ?','text',$array)).'<br>';
// You can disconnect from the database with:
echo '<br>see getRow in action:<br>';
echo Var_Dump::display($db->getRow('SELECT * FROM numbers WHERE number = ?',array('integer','text','text'),$array)).'<br>';
echo '<br>see getCol in action:<br>';
Expand Down Expand Up @@ -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
)).'<br>';
if($manager->database) {
echo Var_Dump::display($manager->database->debugOutput()).'<br>';
}

// this is the database definition as an array
echo Var_Dump::display($manager->database_definition).'<br>';
}
echo '<br>just a simple delete query:<br>';
echo Var_Dump::display($db->query('DELETE FROM numbers')).'<br>';
// You can disconnect from the database with:
$db->disconnect()
?>
46 changes: 22 additions & 24 deletions tests/MDB_test.php
Expand Up @@ -23,39 +23,39 @@
}
echo $db_type.'<br>';

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')).'<br>';
echo 'updating database from xml schema file<br>';
}

// 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.
if (MDB::isError($db)) {
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')).'<br>';
echo 'updating database from xml schema file<br>';
}

// happy query
$query ='SELECT * FROM test';
echo 'query for the following examples:'.$query.'<br>';
Expand Down Expand Up @@ -138,7 +138,6 @@
$array = array(4);
echo '<br>see getOne in action:<br>';
echo Var_Dump::display($db->getOne('SELECT trans_en FROM numbers WHERE number = ?','text',$array)).'<br>';
// You can disconnect from the database with:
echo '<br>see getRow in action:<br>';
echo Var_Dump::display($db->getRow('SELECT * FROM numbers WHERE number = ?',array('integer','text','text'),$array)).'<br>';
echo '<br>see getCol in action:<br>';
Expand Down Expand Up @@ -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
)).'<br>';
if($manager->database) {
echo Var_Dump::display($manager->database->debugOutput()).'<br>';
}

// this is the database definition as an array
echo Var_Dump::display($manager->database_definition).'<br>';
}
echo '<br>just a simple delete query:<br>';
echo Var_Dump::display($db->query('DELETE FROM numbers')).'<br>';
// You can disconnect from the database with:
$db->disconnect()
?>

0 comments on commit 849ee65

Please sign in to comment.