Exemplo n.º 1
0
            }
            if (func_num_args() > 1) {
                $args = func_get_args();
                $query = call_user_func_array("sprintf", $args);
            }
            try {
                $this->QUERY = $query;
                $this->RESULT = mysql_query($query);
                if (!$this->RESULT) {
                    throw new Exception('Error: Query ($query) : ' . mysql_error() . print_r($this));
                } else {
                    return $this->RESULT;
                }
            } catch (Exception $e) {
                echo $e->GetMessage();
            }
        } else {
            return "Error: No connection has been established to the database. Cannot stat query.";
        }
    }
    /** Get Database name
     * This method return the name of the current open db */
    function CurrentDb()
    {
        $r = mysql_query("SELECT DATABASE()");
        return mysql_result($r, 0);
    }
}
// get instance of mysql db
$mysql = MySqlDb::getInstance();
Exemplo n.º 2
0
ini_set('display_errors', '1');
include_once './db/dbconnect.php';
$school_name = $_GET['inpSchoolName'];
$school_type = $_GET['inpSchoolType'];
$school_addrlane1 = $_GET['inpaddrlane1'];
$school_addrlane2 = $_GET['inpaddrlane2'];
$school_city = $_GET['inpcity'];
$school_state = $_GET['inpstate'];
$school_phone = $_GET['inpphone'];
$school_email = $_GET['inpEmail'];
$school_overview = $_GET['inpoverview'];
$school_ann_fees = $_GET['inpAnualFee'];
$format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml';
$result = '';
$link = NULL;
$db = MySqlDb::getInstance();
try {
    $link = $db->connect('localhost', 'root', 'ramesha', 'mydb');
} catch (Exception $e) {
    $result = $e->getMessage();
}
$query = "INSERT INTO school(school_name, school_addr, school_lat, school_lng, school_city, school_state, school_type, school_ann_fees, school_phone, school_email, school_overview, school_imgs_path, school_doa) VALUES ('{$school_name}','{$school_addrlane1} . {$school_addrlane2}', 10.000, 10.000, '{$school_city}', '{$school_state}', '{$school_type}', '{$school_ann_fees}', '{$school_phone}', '{$school_email}', '{$school_overview}', 'file', CURRENT_TIMESTAMP);";
$db->insert($query);
if ($format == 'json') {
    header('Content-type: application/json');
    echo json_encode('Everything is fine..');
} else {
    header('Content-type: application/xml');
    echo '<result>';
    echo '<value>';
    echo 'Data inserted successfully.';