cvs: pear /LiveUser/docs/examples demodata.php
| From: | Lukas Smith | Date: | Thu, 09 Jun 2005 14:14:24 +0000 |
| Subject: | cvs: pear /LiveUser/docs/examples demodata.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-32443@lists.php.net to get a copy of this message | ||
lsmith Thu Jun 9 10:14:24 2005 EDT
Modified files:
/pear/LiveUser/docs/examples demodata.php
Log:
- added support for GET
- minor fixes
http://cvs.php.net/diff.php/pear/LiveUser/docs/examples/demodata.php?r1=1.5&r2=1.6&ty=u
Index: pear/LiveUser/docs/examples/demodata.php
diff -u pear/LiveUser/docs/examples/demodata.php:1.5 pear/LiveUser/docs/examples/demodata.php:1.6
--- pear/LiveUser/docs/examples/demodata.php:1.5 Thu Jun 9 09:29:49 2005
+++ pear/LiveUser/docs/examples/demodata.php Thu Jun 9 10:14:24 2005
@@ -20,6 +20,8 @@
* Example usage: php demodata.php -d mysql://root:@localhost/lu_test -f
* example5/demodata.xml
*
+ * Alternativly you can also call the script from the web using GET
+ * demodata.php?help=1&dsn=mysql://root:@localhost/lu_test&file=example5/demodata.xml
*
* PHP version 4 and 5
*
@@ -45,53 +47,64 @@
* @author Arnaud Limbourg <arnaud@limbourg.com>
* @copyright 2002-2005 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
- * @version CVS: $Id: demodata.php,v 1.5 2005/06/09 13:29:49 lsmith Exp $
+ * @version CVS: $Id: demodata.php,v 1.6 2005/06/09 14:14:24 lsmith Exp $
* @link http://pear.php.net/LiveUser
*/
require_once 'MDB2/Schema.php';
-require_once 'Console/Getopt.php';
-require_once 'System.php';
-$argv = Console_Getopt::readPHPArgv();
+$dsn = $file = '';
-$shortoptions = "h?d:f:";
+if ($_SERVER['REQUEST_METHOD'] == 'GET') {
+ echo '<pre>';
+ if (isset($_GET['help'])) {
+ printHelp();
+ }
+ if (isset($_GET['file'])) {
+ $file = $_GET['file'];
+ }
+ if (isset($_GET['dsn'])) {
+ $dsn = $_GET['dsn'];
+ }
+} else {
+ require_once 'Console/Getopt.php';
+ $argv = Console_Getopt::readPHPArgv();
-$longoptions = array('file=', 'dsn=');
+ $shortoptions = "h?d:f:";
+ $longoptions = array('file=', 'dsn=');
-$dsn = $file = '';
+ $con = new Console_Getopt;
+ $args = $con->readPHPArgv();
+ array_shift($args);
+ $options = $con->getopt($args, $shortoptions, $longoptions);
-$con = new Console_Getopt;
-$args = $con->readPHPArgv();
-array_shift($args);
-$options = $con->getopt($args, $shortoptions, $longoptions);
-
-if (PEAR::isError($options)) {
- printHelp($options);
-}
-
-$options = $options[0];
-foreach ($options as $opt) {
- switch ($opt[0]) {
- case 'd':
- case '--dsn':
- $dsn = $opt[1];
- break;
- case 'f':
- case '--file':
- $file = $opt[1];
- break;
- case 'h':
- case '--help':
- printHelp();
- break;
+ if (PEAR::isError($options)) {
+ printHelp($options);
+ }
+
+ $options = $options[0];
+ foreach ($options as $opt) {
+ switch ($opt[0]) {
+ case 'd':
+ case '--dsn':
+ $dsn = $opt[1];
+ break;
+ case 'f':
+ case '--file':
+ $file = $opt[1];
+ break;
+ case 'h':
+ case '--help':
+ printHelp();
+ break;
+ }
}
}
/******************************************************************
Begin sanity checks on arguments
******************************************************************/
-if ($dsn == '' && $file == '') {
+if ($dsn == '' || $file == '') {
printHelp();
}
@@ -115,7 +128,7 @@
exit();
}
-$res = $manager->updateDatabase($lu_example_data, false, array('database' =>
$dsninfo['database']));
+$res = $manager->updateDatabase($file, false, array('database' =>
$manager->db->getDatabase()));
if (PEAR::isError($res)) {
print "I could not populate the database, see error below\n";
@@ -150,6 +163,9 @@
php demodata.php -d mysql://root:@localhost/lu_test -f example5/demodata.xml
+Alternativly you can also call the script from the web using GET
+
+demodata.php?help=1&dsn=mysql://root:@localhost/lu_test&file=example5/demodata.xml
');
exit;
}