Exemple #1
0
$db->print_last_query();
// This I find very handy.  You can build an array as you are working through,
// for example, POST variables and validating the data or formatting the data
// etc.  By defaul, the class will add slashes (addslashes()) to all string data
// being input using this function.  you can override that by doing:
// $db->auto_slashes = false;
// You cannot perform any MySQL functions when using insert_array() as the the
// function will be enclosed in quotes and not executed.  If you have some fancy
// MySQL functions you'll want to use the insert_sql() function in which you
// provide all the sql.
// Also, it's worth pointing out that if the table in which data is being inserted
// has an auto_increment value (as this one does), then the function will return
// that value which is generated.
echo "<br>Adding data to the table from an array...<br>";
$data = array('user_name' => 'Micah Carrick', 'email' => '*****@*****.**', 'date_added' => '04/13/2003 4:12 PM', 'age' => 24, 'random_text' => "This ain't no regular text.  It's got some \"quotes\" and what not!");
$user_id = $db->insert_array('users', $data);
if (!$user_id) {
    $db->print_last_error(false);
}
$db->print_last_query();
$db->dump_query("SELECT * FROM users WHERE user_id={$user_id}");
// This is similar to the above, only it updates the data rather than insert. Also
// you'll notice that in the first one we used a string to represent the date
// and this time we're using the time function to generate a timestamp.  This is
// done to illustrate the class' ability to convert the date and time formats
// to a MySQL compatible format.  I like that alot :)
echo "<br>Updating the data in the table by changing the date_added... ";
$data = array('date_added' => time());
$rows = $db->update_array('users', $data, "user_id={$user_id}");
if (!$rows) {
    $db->print_last_error(false);
Exemple #2
0
    }
}
if (!empty($_REQUEST['youtube_url'])) {
    require_once 'db/db.class.php';
    checkForSpam();
    // Open the DB connection
    $db = new db_class();
    if (!$db->connect($GLOBALS['db_hostname'], $GLOBALS['db_username'], $GLOBALS['db_password'], $GLOBALS['db_name'], true)) {
        $db->print_last_error(false);
    }
    // Get the user info into the DB
    $user_data = $stuffer->getUserData();
    $sql = "SELECT id from users where username = '******'username']) . "';";
    $user_id = $db->select_one($sql);
    if (!$user_id) {
        $user_id = $db->insert_array('users', $user_data);
    }
    // cram the video into the db
    $youtube_url = mysql_real_escape_string($_REQUEST['youtube_url']);
    $create_time = empty($create_time) ? time() : $create_time;
    $video_data = array('youtube_url' => $youtube_url, 'type' => 'video', 'user_id' => $user_id, 'create_time' => time());
    $video_id = $db->insert_array('images', $video_data);
    if (is_numeric($video_id)) {
        header('Location: http://www.braincrave.org/?id=' . $video_id . "&success=1");
    } else {
        $stuffer->error("Really?  You screwed this up?  All you had to do was paste in ONE THING.  Maybe you should try again.");
    }
} else {
    $image_id = $stuffer->stuff();
    if ($image_id) {
        // require the twitter library