php+mysqli實現批量替換資料庫表首碼的方法,mysqli首碼_PHP教程

來源:互聯網
上載者:User

php+mysqli實現批量替換資料庫表首碼的方法,mysqli首碼


本文執行個體講述了php+mysqli實現批量替換資料庫表首碼的方法。分享給大家供大家參考。具體分析如下:

在php中有時我們要替換資料庫中表首碼但是又不苦於一個個表去修改首碼,這裡我自己寫了一個mysqli批量替換資料庫表首碼的php程式,感興趣的朋友可以參考一下,代碼如下:
複製代碼 代碼如下:<?php
header ( 'http-equiv="Content-Type" content="text/html; charset=utf-8"' );
$DB_host = "localhost"; //資料庫主機
$DB_user = "root"; //資料庫使用者
$DB_psw = "root3306"; //資料庫密碼
$DB_datebase = "gk_yue39_com"; //資料庫名
$DB_charset = "utf8"; //資料庫字元集
$dbprefix="yue392_com_";
$new_dbprefix="yue39_com_";
$db = new mysqli ( $DB_host, $DB_user, $DB_psw ); //執行個體化對象

//檢查串連
if (mysqli_connect_errno ()) {
printf ( "Connect failed: %sn", mysqli_connect_error () );
exit ();
}

$db->select_db ( $DB_datebase ); //選擇操作資料庫

$db->set_charset ( $DB_charset ); //設定資料庫字元集

//執行一個查詢
$sql = 'show tables';
$result = $db->query ( $sql );

echo $result->num_rows . ' 行結果 ' . $result->field_count . ' 列內容
';

//$result->data_seek('5');//從結果集中第5條開始取結果

echo '























'; //迴圈輸出欄位名 //$result->field_seek(2);//從欄位集中第2條開始取結果 while ( true == ($field = $result->fetch_field ()) ) { echo ' '; } //迴圈輸出查詢結果 while ( true == ($row = $result->fetch_assoc ()) ) { echo ' '; foreach ( $row as $col ) { $sql="rename table `".$col."` to `".str_replace ( $dbprefix, $new_dbprefix, $col)."`"; if($db->query ( $sql )){ echo ' '; }else{ echo ' '; } } echo ' '; } echo '
' . $result->current_field . '_' . $field->name . '(' . $field->length . ')
' . $sql. ' success' . $sql. ' failed
';
$result->free ();//釋放結果集
$db->close (); //關閉串連
?>

希望本文所述對大家的php程式設計有所協助。

http://www.bkjia.com/PHPjc/934933.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/934933.htmlTechArticlephp+mysqli實現批量替換資料庫表首碼的方法,mysqli首碼 本文執行個體講述了php+mysqli實現批量替換資料庫表首碼的方法。分享給大家供大家參考。...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.