コード例 #1
0
ファイル: install.php プロジェクト: rupertchen/cmatic
     if (!preg_match('/^[a-zA-Z][_a-zA-Z0-9]*$/', $requestParams['tablePrefix'])) {
         $errorMessages[] = 'The table prefix must start with a letter and may only contain letters, numbers, and underscores';
     }
 }
 if (count($errorMessages) > 0) {
     throw new CmaticInstallerException($errorMessages);
 }
 try {
     // TODO: Probably should refactor this logic out into a function
     // Create the schema in the DB
     // Open the file, replace the table prefix, strip comments
     $schemaFile = 'schema/postgres8.sql';
     $sql = fread(fopen($schemaFile, 'r'), filesize($schemaFile));
     $sql = preg_replace('/cmatic_/', $requestParams['tablePrefix'], $sql);
     // Strip away inline comments beginning with "--" or "//"
     $sql = PdoHelper::removeComments($sql);
     $db = new PDO(PdoHelper::getPgsqlDsn($requestParams['host'], $requestParams['port'], $requestParams['db']), $requestParams['user'], $requestParams['password']);
     // The squeaky wheel gets the oil, make it known when things went wrong.
     $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $db->beginTransaction();
     try {
         foreach ($sql as $singleSql) {
             $singleSql = trim($singleSql);
             if (!empty($singleSql)) {
                 $db->exec($singleSql);
             }
         }
         $db->commit();
         // This should be in a "finally" block, but PHP doesn't have such a thing?!
         $db = null;
     } catch (Exception $e) {