本代码属于单表转换,在开始转换之前,假设你已经对应sqlite3数据的某张表在mysql数据库中建立相同名称的表和列,这里假设表中的列为,colname1,colname2,colname3...
| <?php set_time_limit(0);
define( 'CONNECTSTRING' , "sqlite:" .dirname( __FILE__ ). "/sqlite3_db_name.db" );
define( 'USERNAME' , 'username' );
define( 'PASSWORD' , 'password' );
define( 'CHARSET' , 'SET NAMES utf8' );
$db = 'localhost' ;
$user = 'usernmae' ;
$pass = 'password' ;
$dbname = 'mysql_db_name' ;
$dbh =null;
if ( $dbh = new PDO(CONNECTSTRING, USERNAME, PASSWORD, array (PDO::MYSQL_ATTR_INIT_COMMAND => CHARSET))){
$dbh ->beginTransaction();
ini_set ( 'memory_limit' , '-1' );
$sth = $dbh ->prepare( 'SELECT * FROM sqlite3_table_name' );
$sth ->execute();
$result = $sth ->fetchAll();
$conn =mysql_connect( $db , $user , $pass ) or die ( "conn error" );
mysql_query( "set names 'utf8'" );
mysql_select_db( $dbname );
foreach ( $result as $row ){
$sql = "" ;
$sql = "INSERT INTO mysql_db_name(colname1,colname2,colname3) VALUES('" ;
$sql = $sql . $row [ 'colname1' ]. "','" . $row [ 'colname2' ]. "','" . $row [ 'colname3' ]. "')" ;
mysql_query( $sql );
}
mysql_close( $conn );
$dbh =null;
}
?>
|
新手可以看看,高手勿喷,谢谢。
打开App,阅读手记