예제 #1
0
                    $error = $e->getMessage();
                }
            } else {
                $error = ERR_NO_CREATEDB;
            }
        }
    } else {
        // keep original error
        $error = $hold_error;
    }
}
// leave if we are already connected to a database from earlier input
if ($connection && empty($error)) {
    $currentDb = $connection->getDatabase();
    if (!empty($currentDb)) {
        $settings['DB_PARAMETERS'] = serialize(getDbConnectionParams());
        $_SESSION['settings'] = $settings;
        $wizard->redirectToPage('+1');
        exit;
    }
}
if ($connection) {
    $platform = $connection->getDatabasePlatform();
    try {
        $sql = $platform->getListDatabasesSQL();
        $dbResults = $connection->fetchAll($sql);
    } catch (Exception $e) {
        $dbResults = false;
    }
    $dbIgnored = $wizard->configs['db_types'][$settings['DB_DRIVER']]['ignoredb'];
    if ($dbResults) {
예제 #2
0
/**
 * getDbConnection - get database connection based on current setting
 *
 * @param string &$error will be set with any error encountered
 *
 * @return Connection a database connection instance
 */
function getDbConnection(&$error)
{
    //New database connector
    $config = new \Doctrine\DBAL\Configuration();
    $connectionParams = getDbConnectionParams();
    try {
        $instance = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
    } catch (Exception $e) {
        $error = $e->getMessage();
        return false;
    }
    if (!$instance) {
        $error = ERR_NO_DBCONNECTION;
        return false;
    } else {
        try {
            $instance->connect();
        } catch (Exception $e) {
            $error = $e->getMessage();
            return false;
        }
    }
    return $instance;
}
예제 #3
0
파일: db.php 프로젝트: arteam/orders-system
/**
 * Insert a new fulfillment
 *
 * @param $bidId
 * @param $product
 * @param $amount
 * @param $royalty
 * @param $price
 * @param $customerId
 * @param $placeTime
 * @param $contractorId
 * @return  boolean
 */
function insertFulfillment($bidId, $product, $amount, $price, $royalty, $customerId, $placeTime, $contractorId)
{
    list($dbName, $user, $pass) = getDbConnectionParams('fulfillments');
    $pdo = buildPDO($dbName, $user, $pass);
    try {
        $stmt = $pdo->prepare("insert into fulfillments(bid_id, product, amount, price, royalty, customer_id, place_time,\n                   fullfill_time, contractor_id) values\n                   (:bid_id, :product, :amount, :price, :royalty, :customer_id, :place_time, now(), :contractor_id)");
        $stmt->bindParam(":bid_id", $bidId, PDO::PARAM_INT);
        $stmt->bindParam(":product", $product);
        $stmt->bindParam(":amount", $amount, PDO::PARAM_INT);
        $stmt->bindParam(":price", $price);
        $stmt->bindParam(":royalty", $royalty);
        $stmt->bindParam(":customer_id", $customerId);
        $stmt->bindParam(":place_time", $placeTime);
        $stmt->bindParam(":contractor_id", $contractorId);
        return $stmt->execute();
    } catch (Exception $e) {
        error_log("Unable to insert a fulfillment with bidId={$bidId} from customer={$customerId}\n        to contractor={$contractorId}", e);
        return false;
    } finally {
        $stmt = null;
        $pdo = null;
    }
}