Exemplo n.º 1
0
function pdo_test_connection($connection_string, $dbtype)
{
    $info = parse_connection_string($connection_string);
    //$link = mysql_connect("$info->host:$info->port", $info->user_id, $info->password) or die("ServerError:Could not connect to host '$info->host'");
    try {
        //var_dump($info);
        $conn = new PDO($dbtype . ':host=' . $info->host . ';dbname=' . $info->database, $info->user_id, $info->password);
        return "success";
    } catch (Exception $e) {
        return $e->getMessage();
    }
}
Exemplo n.º 2
0
        $str .= ", '" . $k . "' => '" . $v . "'";
    }
    $i++;
}
$str .= "));\n";
if ($demo === true) {
    if ($otherset['createconn'] == 'yes') {
        $str .= "// Demo Mode creating connection \n";
        $str .= "include_once " . "\$" . "DRIVER_PATH." . "'jqGridPdo.php'; \n";
        $str .= "\$" . "conn = new PDO(DB_DSN, DB_USER, DB_PASSWORD);\n";
        $str .= $the_name . "->setConnection( " . "\$" . "conn" . " );\n";
    }
} else {
    if (isset($otherset['createconn']) && $otherset['createconn'] == 'yes') {
        $dbtype = $otherset['dbtype'];
        $condobj = parse_connection_string($otherset['connstring']);
        $jq_conn = "\$" . $otherset['conname'];
        $str .= "// Create the connection \n";
        //$str .= "if(".$the_name."->oper != 'no') {\n";
        switch ($dbtype) {
            case 'mysql':
            case 'pgsql':
            case 'sqlite':
                $str .= "include_once " . "\$" . "DRIVER_PATH." . "'jqGridPdo.php'; \n";
                $str .= $jq_conn . " = new PDO('" . $dbtype . ":host=" . $condobj->host . ";dbname=" . $condobj->database . "','" . $condobj->user_id . "','" . $condobj->password . "');\n";
                break;
        }
        $str .= $the_name . "->setConnection( " . "\$" . $otherset['conname'] . ");\n";
        //$str .= "}\n";
    } else {
        if (isset($otherset['createconn']) && $otherset['createconn'] == 'no') {
Exemplo n.º 3
0
$connstr = jqGridUtils::GetParam('conn');
$dbtype = jqGridUtils::GetParam('dbtype');
$action = jqGridUtils::GetParam('action');
$sqlstr = jqGridUtils::GetParam('sqlstring');
//var_dump($sqlstr);
if ($action == 'test') {
    if ($dbtype == 'mysql' || $dbtype == 'pgsql' || $dbtype == 'sqlite') {
        echo pdo_test_connection($connstr, $dbtype);
    }
}
//	var_dump($action);
if ($action == 'genform') {
    if ($dbtype == 'mysql' || $dbtype == 'pgsql' || $dbtype == 'sqlite') {
        include '../php/jqGridPdo.php';
        ini_set("display_errors", 1);
        $info = parse_connection_string($connstr);
        try {
            $conn = new PDO($dbtype . ':host=' . $info->host . ';dbname=' . $info->database, $info->user_id, $info->password);
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sqlstr = jqGridDB::limit($sqlstr, $dbtype, 1, 0);
            //var_dump($sqlstr);
            $stmt = jqGridDB::prepare($conn, $sqlstr, null);
            $ret = jqGridDB::execute($stmt);
            $metasql = array();
            if ($ret) {
                $meta = array();
                $colcount = jqGridDB::columnCount($stmt, null);
                for ($i = 0; $i < $colcount; $i++) {
                    $meta = jqGridDB::getColumnMeta($i, $stmt);
                    $metasql[] = array("name" => $meta['name'], "type" => jqGridDB::MetaType($meta, $dbtype), "len" => $meta['len']);
                }