Esempio n. 1
0
function verify_choices(array &$choices, $change_mind_question = null)
{
    if ($change_mind_question && user_yesno($change_mind_question)) {
        return;
    }
    $keys = array_keys($choices);
    while (true) {
        print_error("\n");
        $i = 0;
        foreach ($choices as $key => $value) {
            $i++;
            print_error("{$i}. {$key} [{$value}]\n");
        }
        print_error("Select value to change or enter to continue: ");
        $choice = trim(fgets(STDIN));
        if (0 == strlen($choice)) {
            break;
        } else {
            if (!array_key_exists($choice - 1, $keys)) {
                print_error("Invalid choice. Try again.\n\n");
                continue;
            }
        }
        $key = $keys[$choice - 1];
        print_error("Select a new value for {$key}: ");
        $choices[$key] = trim(fgets(STDIN));
    }
}
Esempio n. 2
0
// load a database connection
//
// @author 		Joseph Mastey <*****@*****.**>
// @author		$Author$
// @version		$Id$
// @copyright	Copyright (c) JRM Ventures LLC, 2010-
//
require_once "local.php";
require_once "interaction.php";
if (!isset($use_default_connection) || !$use_default_connection) {
    print_error("Current settings:\n");
    foreach ($db_config_array as $key => $value) {
        print_error(sprintf("%-10s: %s\n", $key, $value));
    }
    if (!user_yesno("Use these settings?")) {
        verify_choices($db_config_array);
    }
}
$db_conn = mysql_connect($db_config_array['host'], $db_config_array['username'], $db_config_array['password']);
if (!$db_conn) {
    throw new Exception("Failed to connect to database as {$dbConfig->username}");
}
if (!mysql_select_db($db_config_array['dbname'], $db_conn)) {
    throw new Exception("Couldn't select database {$db_config_array['dbname']}.");
}
function start_db_transaction()
{
    _autocommit(0);
    mysql_query("start transaction") or die(mysql_error());
}