From 8431df19ec14adca40cb91f84c98e605eb5d4cd0 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Thu, 14 Aug 2014 08:06:49 +1000 Subject: [PATCH] Better error checking and more informative messages for initial db build --- build-base.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/build-base.php b/build-base.php index ceaa315f47..8522579dca 100644 --- a/build-base.php +++ b/build-base.php @@ -5,18 +5,30 @@ include( "config.php" ); -$sql_file = $sqlfile ?: 'build.sql'; -$sql_fh = fopen( $sql_file, 'r' ); +if (!isset($sql_file)) { + $sql_file = 'build.sql'; +} +$sql_fh = fopen( $sql_file, 'r' ); +if ($sql_fh === FALSE) { + echo( "ERROR: Cannot open SQL build script " . $sql_file . "\n" ); + exit(1); +} + $connection = mysql_connect( $config['db_host'], $config['db_user'], $config['db_pass'] ); +if ($connection === FALSE) { + echo( "ERROR: Cannot connect to database: " . mysql_error() . "\n" ); + exit(1); +} + mysql_select_db( $config['db_name'] ); while( !feof( $sql_fh ) ) { - $line = fgetss( $sql_fh ); + $line = fgetss( $sql_fh ); if(!empty($line)) { $creation = mysql_query( $line ); if( !$creation ) { - echo( mysql_error() . "\n" ); + echo( "WARNING: Cannot execute query (" . $line . "): " . mysql_error() . "\n" ); } } }