本文整理汇总了PHP中DbConnect::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP DbConnect::getInstance方法的具体用法?PHP DbConnect::getInstance怎么用?PHP DbConnect::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbConnect
的用法示例。
在下文中一共展示了DbConnect::getInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$db = DbConnect::getInstance();
$this->conn = $db->getConnection();
if (!$this->conn) {
throw new Exception("cannot connect to server");
}
return $this->conn;
}
示例2: backupDbTwToken
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: __construct
public function __construct()
{
$this->conn = DbConnect::getInstance()->connectDb();
}