< ?php backup_tables('localhost','root','xxxxxxx','dbname'); /* backup the db OR just a table $hostname 主機名稱 $username 帳號 $password 密碼 $dbname 資料庫名稱 */ function backup_tables($hostname,$username,$password,$dbname,$tables = '*') { $link = mysql_connect($hostname,$username,$password); mysql_select_db($dbname,$link); //get all of the tables if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //cycle through foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+'); fwrite($handle,$return); fclose($handle); } ? >
myAdBanner
2013年9月6日 星期五
backup_tables
php 連接 mssql
我的程式
在連接 mssql 時出現這個問題
“Warning mssql_connect()[function.mssql-connect]: Unable to connect to server:”
解決方法
1.修改 php.ini 打開php.ini
找到 ;extension=php_mssql.dll
打extension=php_mssql.dll 前面的 “;” 刪除便可以了
2.下載 ntwdblib.dll
之後把他複製/取代 你電腦上的
Apache/bin/ntwdblib.dll 和 php/ntwdblib.dll
3. Apache Restart
再測就OK了
<?php //mssql.secure_connection = On // Need to upload ntwdblib.dll from net $myServer = ".\SQLEXPRESS"; // host/instance_name $myUser = "sa"; // username $myPass = "xxxxxxxx"; // paasword $myDB = "mydb"; // database name // connection to the database $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn’t connect to SQL Server on $myServer"); // select a database to work with $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn’t open database $myDB"); echo "You are connected to the " . $myDB . " database on the " . $myServer . "."; $query = "SELECT top 10 * FROM Account"; // your database query $result = mssql_query($query); while($row = mssql_fetch_assoc($result)) { print_r($row); } // close the connection mssql_close($dbhandle); ?>
在連接 mssql 時出現這個問題
“Warning mssql_connect()[function.mssql-connect]: Unable to connect to server:”
解決方法
1.修改 php.ini 打開php.ini
找到 ;extension=php_mssql.dll
打extension=php_mssql.dll 前面的 “;” 刪除便可以了
2.下載 ntwdblib.dll
之後把他複製/取代 你電腦上的
Apache/bin/ntwdblib.dll 和 php/ntwdblib.dll
3. Apache Restart
再測就OK了
訂閱:
文章 (Atom)