From e9fa1aafb0d6f84fc7dacc6bfd5c26cfbf5d1551 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Wed, 24 May 2017 09:01:51 +0000 Subject: [PATCH] modelGenerator: catch the connect Exception to database correctely git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3726 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- tools/modelGenerator.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/modelGenerator.php b/tools/modelGenerator.php index 3eb86a7..f429325 100755 --- a/tools/modelGenerator.php +++ b/tools/modelGenerator.php @@ -35,10 +35,14 @@ class modelGenerator { $getopts = new \getopts (); $getopts->add ("Help", "?h", "help", "Help of the software"); - $getopts->add ("DSN", "", "dsn:", "DSN - Data Source Name", "dsn"); - $getopts->add ("Output", "o:", "output:", "Output directory", "dir"); + $getopts->add ("DSN", "", "dsn:", "DSN - Data Source Name\n". + " Exemple : --dsn \"mysql:dbname=DBNAME\"", + "dsn"); + $getopts->add ("Output", "o:", "output:", + "Output directory, ./models by default", "dir"); $getopts->add ("Namespace", "n:", "namespace:", - "The namespace (if '', not added)", "namespaceName"); + "The namespace (if '', not added), models by default", + "namespaceName"); $getopts->add ("Username", "u:", "username:", "Username to connect", "username"); $getopts->add ("Password", "p:", "password:", "Password to connect", @@ -64,9 +68,17 @@ class modelGenerator $this->dsn = $dsn; $this->modelsDir = $modelsDir; $this->namespaceName = $getopts->get ("Namespace"); - $this->db = new \dblayeroo ($dsn, - $getopts->get ("Username"), - $getopts->get ("Password")); + try + { + $this->db = new \dblayeroo ($dsn, + $getopts->get ("Username"), + $getopts->get ("Password")); + } + catch (\Exception $e) + { + file_put_contents ("php://stderr", $e->getMessage ()."\n"); + exit (3); + } } /** List all the existing tables in the database