Пример #1
0
 public function __construct()
 {
     $db = DbConnect::getInstance();
     $this->conn = $db->getConnection();
     if (!$this->conn) {
         throw new Exception("cannot connect to server");
     }
     return $this->conn;
 }
Пример #2
0
function backupDbTwToken($database_info, $create_tw_token_table_stmt)
{
    global $docroot;
    //get data base connection;
    $link = getInstance();
    $command = "SET NAMES 'utf8'";
    $stmt = mysqli_prepare($link, $command);
    mysqli_stmt_execute($stmt);
    $command = "select count(*) from tw_token";
    if ($stmt = mysqli_prepare($link, $command)) {
        //mysqli_stmt_bind_param($stmt, 'i', $wid);
        mysqli_stmt_execute($stmt);
        //mysqli_stmt_store_result($stmt);
        mysqli_stmt_bind_result($stmt, $total_row_count);
        mysqli_stmt_fetch($stmt);
    }
    mysqli_stmt_close($stmt);
    $link = DbConnect::getInstance();
    $command = "SET NAMES 'utf8'";
    $stmt = mysqli_prepare($link, $command);
    mysqli_stmt_execute($stmt);
    echo "total row count- tw_token: ", $total_row_count;
    $total_row_count = 20;
    $chunk_size = 10;
    $offset = 0;
    $data = '';
    $data .= $database_info;
    $data .= $create_tw_token_table_stmt;
    $timestamp = date("Y_m_d_H_i_s");
    $link = DbConnect::getInstance();
    while ($offset < $total_row_count) {
        $command = "select tid, user_id_hash, oauth_token, oauth_token_secret, oauth_verifier, user_id, \n\t\t\t                   screen_name, name, location, description, user_image_url, created\n\t \t\t\t\t\tfrom tw_token order by created asc limit {$offset}, {$chunk_size}";
        if ($stmt = mysqli_prepare($link, $command)) {
            //mysqli_stmt_bind_param($stmt, 'i', $wid);
            mysqli_stmt_execute($stmt);
            //mysqli_stmt_store_result($stmt);
            mysqli_stmt_bind_result($stmt, $tid, $user_id_hash, $oauth_token, $oauth_token_secret, $oauth_verifier, $user_id, $screen_name, $name, $location, $description, $user_image_url, $created);
            $screen_name = mysqli_real_escape_string($link, $screen_name);
            $name = mysqli_real_escape_string($link, $name);
            $location = mysqli_real_escape_string($link, $location);
            $description = mysqli_real_escape_string($link, $description);
            $data .= " insert ignore into tw_token(tid, user_id_hash, oauth_token, oauth_token_secret, oauth_verifier, user_id, \n\t\t\t                   screen_name, name, location, description, user_image_url, created ) values ";
            while (mysqli_stmt_fetch($stmt)) {
                $id = empty($id) ? 0 : $id;
                $tid = empty($tid) ? 0 : $tid;
                $data .= "({$tid}, '{$user_id_hash}', '{$oauth_token}', '{$oauth_token_secret}', '{$oauth_verifier}', {$user_id}, \n\t\t\t\t                          '{$screen_name}', '{$name}', '{$location}', '{$description}', '{$user_image_url}', '{$created}'),";
            }
            $data = substr($data, 0, -1);
            $data .= ";\n";
        } else {
            echo "<br>error";
        }
        $offset = $offset + $chunk_size;
    }
    //file_put_contents ( "db_backup_$timestamp.txt", $data, FILE_APPEND );
    file_put_contents($docroot . "/backup_db/backup_db_tw_token_{$timestamp}.sql", $data);
    //file_put_contents('junk.sql','test');
    //file_put_contents ( "backup_db_tw_token.sql", $data);
    echo "--end";
    mysqli_stmt_close($stmt);
    return;
}
Пример #3
0
 public function __construct()
 {
     $this->conn = DbConnect::getInstance()->connectDb();
 }