1.不同数据库类型直接的数据库转换
navicat是个很好的数据库管理软件,可以用它进行不同类型数据库直接的转换,以下链接详细说明如何用navicat将mssql2000数据库转换成mysql数据库。
2.不同结构数据库之间的数据转换
不同数据库结构之间的数据转换存在几个问题,①字段不同,甚至无法一一对应 ②字段格式不同,要转换成目标数据库字段的设计格式 ③sql语句结合php程序转换
这是把之前一个downplus下载系统的数据库转换成phpcms的数据库。
直接上代码,有这方面需求的研究代码吧。
站点1 软件站
①导入所有软件到软件表v95_soft
代码如下 | 复制代码 |
insert into v95_soft(id,catid,title,soft,soft_name,pinyin,thumb,keywords,size,start,inputtime,updatetime,auth,property) select softid,softclassid,seotitle,appname,softname,softphoneticism,IcoImage,softkeywords,softsize,softscore, unix_timestamp(SoftInsertDate),unix_timestamp(softcreatedate),softlicence,softproperty from dp_softlist; |
②写sql设status为99
代码如下 | 复制代码 |
update v95_soft set status=99; |
③到后台更新全站url。然后更新title为空的,软件名称
代码如下 | 复制代码 |
update v95_soft set title=soft_name where title=''; |
④导入到v95_soft_date
代码如下 | 复制代码 |
insert into v95_soft_data(id,content,language,website,icon,softos) select softid,softintro,softlanguage,softauthorurl,IcoImage,softos from dp_softlist; |
⑤执行php转换程序,导入下载地址
http://www.xxx.com/admin.php?m=admin&c=index&a=down
代码如下 | 复制代码 |
public function down(){ set_time_limit(0); $sql = "select id from v95_soft_data "; $result = $this->db->query($sql); while ($r = mysql_fetch_assoc($result)) { //$softid = 11; $softid = $r['id']; $sql = "select fileurlname,fileurl,fileftpid from dp_softfiles where softid = $softid "; $downfile = $this->db->query($sql); $downfiles = array(); while ($r = mysql_fetch_assoc($downfile)) { $isbigfile = 0; if (!$r['fileurlname']) { $sql = "select soft_name from v95_soft where id = $softid "; $result2 = $this->db->query($sql); while ($r2 = mysql_fetch_assoc($result2)) { $soft_name = $r2['soft_name']; } $r['fileurlname'] = $soft_name; } if(12 == $r['fileftpid']){ $isbigfile = 1; } $downfiles[] = array('fileurl'=>$r['fileurl'],'filename'=>$r['fileurlname'],'isbigfile'=>$isbigfile); } $downfiles = array2string($downfiles); //var_dump($downfiles);exit; $sql = "update v95_soft_data set downfiles = '$downfiles' where id = $softid "; $this->db->query($sql); } echo 'OK'; } |
⑥软件单位和大小转换
代码如下 | 复制代码 |
update v95_soft set size=size/1000,unit='MB' where size>1000 and size<1000000; update v95_soft set size=size/1000000,unit='GB' where size>1000000; |
⑦导入标签,到v95_keyword和v95_keyword_data
代码如下 | 复制代码 |
insert into v95_keyword(id,keyword) select tagid,tagname from dp_tag; update v95_keyword set siteid=1; |
⑧执行php转换程序,匹配标签到关键字
http:///admin.php?m=admin&c=index&a=transe
php代码:
代码如下 | 复制代码 |
public function transe(){ set_time_limit(0); $sql = "select tagid,softidlist from dp_tag"; $result = $this->db->query($sql); while($r = mysql_fetch_assoc($result)){ //var_dump($r);exit; $tags = $r['softidlist']; $tags = explode(",", $tags); $tags = array_filter($tags); //var_dump($tags);exit; $tagid = $r['tagid']; //echo $tagid;exit; foreach ($tags as $tag) { $sql="insert into v95_keyword_data(tagid,siteid,contentid) values('$tagid','1','$tag')"; $this->db->query($sql); } } echo 'OK'; } |
调整格式
代码如下 | 复制代码 |
update v95_keyword_data set contentid=CONCAT(contentid,'-12'); |
⑩点击率
代码如下 | 复制代码 |
insert into v95_hits(hitsid,catid) select id,catid from v95_soft; update v95_hits as a left join dp_softlist as b on a.hitsid=b.softid |
十一 相关文章
代码如下 | 复制代码 |
http:///admin.php?m=admin&c=index&a=related (最后执行,很慢) public function related(){ |
站点2 单机站
①由于类别不同,要先把原先类别改成现在的类别id
代码如下 | 复制代码 |
update downtb set ClassID=217 where ClassID=1; update downtb set ClassID=218 where ClassID=2; update downtb set ClassID=219 where ClassID=3; update downtb set ClassID=220 where ClassID=4; update downtb set ClassID=221 where ClassID=5; update downtb set ClassID=222 where ClassID=6; update downtb set ClassID=223 where ClassID=7; update downtb set ClassID=224 where ClassID=8; update downtb set ClassID=225 where ClassID=9; update downtb set ClassID=226 where ClassID=10; update downtb set ClassID=233 where ClassID=11; |
②导入主表到v95_danji
代码如下 | 复制代码 |
insert into v95_danji(id,catid,title,thumb,soft_name,size,inputtime,updatetime,auth,language,downurl) select DownID,ClassID,SeoTitle,thumb,DownName,Sizes,unix_timestamp(addtime),unix_timestamp(addtime), Shouquan,Languages,DownIntro1 from downtb; |
③后台更新全站url,然后设status为99,没有seo标题的采用单机游戏名称
代码如下 | 复制代码 |
update v95_danji set status=99; update v95_danji set title=soft_name where title=''; |
④大小单位转换,下载地址格式调整
代码如下 | 复制代码 |
update v95_danji set size=size/1000,unit='MB' where size>1000 and size<1000000; update v95_danji set size=size/1000000,unit='GB' where size>1000000; update v95_danji set downurl=replace(downurl,'@@**@@本地下载',''); |
⑤修改下载地址
要判断单机游戏填写的地址
如果填写的
代码如下 | 复制代码 |
game=z1.9553.com game2=z2.9553.com |
以此类推
/admin.php?m=admin&c=index&a=downurl(废弃)
⑥导入到v95_danji_data
代码如下 | 复制代码 |
insert into v95_danji_data(id,content,gameid) select DownID,DownIntro,game_id from downtb; |
⑦单机标签转换
1、新增单机站标签到v95_keyword表
代码如下 | 复制代码 |
insert into v95_keyword(id,keyword) select TagID+31616,TagName from tagtb; update v95_keyword set siteid=2 where siteid=0; |
2、执行php程序
此时记住当前v95_keyword中siteid为1的最大id,更改php程序,再填入keywords,执行
http:///admin.php?m=admin&c=index&a=danji
php代码:
代码如下 | 复制代码 |
public function danji(){ set_time_limit(0); $sql = "select DownID,ToTagIDs from downtb"; $result = $this->db->query($sql); while ($r = mysql_fetch_assoc($result)) { $id=$r['DownID']; $ToTagIDs = explode(",", $r['ToTagIDs']); $ToTagIDs = array_filter($ToTagIDs); foreach ($ToTagIDs as $key => $value) { $ToTagIDs[$key] = $value+31682; } //var_dump($ToTagIDs);exit; foreach ($ToTagIDs as $tagid) { $sql = "select keyword from v95_keyword where id=$tagid "; $keywords = $this->db->query($sql); while ($r = mysql_fetch_assoc($keywords)) { $keyword[] = $r['keyword']; } } $new_keyword = implode(",", $keyword); $sql="update v95_danji set keywords='$new_keyword' where id=$id"; $this->db->query($sql); unset($keyword); unset($ToTagIDs); } echo 'OK'; } |
3、执行php程序
http:///admin.php?m=admin&c=index&a=danji2
php代码:
代码如下 | 复制代码 |
public function danji2(){ set_time_limit(0); $sql = "select id,keywords from v95_danji"; $result = $this->db->query($sql); while ($r = mysql_fetch_assoc($result)) { $contentid = $r['id']; $keywords = $r['keywords']; $tags = explode(",", $keywords); foreach ($tags as $tag) { $sql = "select id from v95_keyword where keyword='$tag' and siteid=2"; $id = $this->db->query($sql); while ($r = mysql_fetch_assoc($id)) { $id = $r['id']; $sql = "insert into v95_keyword_data(tagid,siteid,contentid) values('$id',2,'$contentid')"; $this->db->query($sql); } } unset($tags); } echo 'OK'; } |
4、修改v95_keyword_data表siteid为2的contentid格式
代码如下 | 复制代码 |
update v95_keyword_data set contentid=CONCAT(contentid,'-14') where siteid=2; |
⑧使点击率可用
代码如下 | 复制代码 |
insert into v95_hits(hitsid,catid) select CONCAT('c-14-',id),catid from v95_danji; |
代码如下 | 复制代码 |
<?php /** header("Content-type:text/html;charset=utf-8"); download('web/www.111cn.net .txt', 'txt文件下载'); $suffix = substr($file,strrpos($file,'.')); //获取文件后缀 //判断给定的文件存在与否 ?> |
代码如下 | 复制代码 |
index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script" width=100% src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script> var chat = { init:function(){ chat.first(); $('#chat_btn').unbind('click').click(function(){ chat.send(); }); $('#my_chat').keyup(function(){ if(event.keyCode == 13){ chat.send(); } }); www.111cn.net }, first:function(){ $.getJSON('data.php',{ action:'first', type:'l' },function(data){ chat.btn_status._true(); $('#mwebtime').html(data.time); $('#chat textarea').val(data.chat); $('#chat textarea').stop(true,true).animate({scrollTop:9999}, 1); chat.socket(); }); }, send:function(){ chat.btn_status._false(); $.getJSON('send.php',{ txt:$('#my_chat').val(), type:'l' },function(data){ if(data.status==200){ chat.btn_status._false(); $('#my_chat').val(''); setTimeout(function(){ chat.btn_status._true(); },2000); } }); }, socket:function(){ $.getJSON('data.php',{ action:'while', type:'l' },function(data){ $('#mwebtime').html(data.time); $('#chat textarea').val(data.chat); $('#chat textarea').stop(true,true).animate({scrollTop:9999}, 1); chat.socket(); }); }, btn_status:{ _false:function(){ $('#chat_btn').html('等待').attr('disabled',true); }, _true:function(){ $('#chat_btn').html('发言').attr('disabled',false); } } } chat.init(); </script> </head> <body> <div id="chat"> <textarea wrap="physical" style="line-height:20px;font-size:12px;height:100px;width:200px;"></textarea> <BR /> <input id="my_chat" type="text" /> <button id="chat_btn" disabled="disabled">发言</button> </div> <div id="mwebtime"></div> </body> </html> data.php <?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pramga: no-cache"); set_time_limit(0); $get = $_GET['action']; $type = $_GET['type']; $file = $type.'.txt'; if(isset($get) && isset($type) && file_exists($file)){ switch($get){ case 'first': $chat = file_get_contents($file); $json=array( 'status' => 200, 'time' => gmdate("s"), 'chat' => $chat, ); echo json_encode($json); break; www.111cn.net case 'while': $oldsize = filesize($file); $newsize = filesize($file); while(true){ if($oldsize!=$newsize){ $chat = file_get_contents($file); $json=array( 'status' => 200, 'time' => gmdate("s"), 'chat' => $chat, ); echo json_encode($json); exit; } clearstatcache(); $newsize = filesize($file); usleep(10000); } break; } } ?> send.php <?php $json = array(); $txt = isset($_GET['txt'])?$_GET['txt']:''; $type = isset($_GET['type'])?$_GET['type']:''; if($txt!=''){ $file = $type.".txt"; if(file_exists($file)){ $fp = fopen($file,"a"); $str = "rn".'Admin:'.$txt; //$str = $txt."n"//linux; fwrite($fp, $str); fclose($fp); $json['status']=200; echo json_encode($json); exit; } } ?> |
例子一
代码如下 | 复制代码 |
//判断远程文件 return $found; |
当然也有很多其它方法,或多或少有些限制和缺陷,如:
(1)使用fopen()函数,它要在allow_url_open开启的状态下,否则会报错。
代码如下 | 复制代码 |
$url = 'http://www.111cn.net /img/qrcode_for_phpddt.JPG'; if(@fopen($url, 'r')) { echo '文件存在'; } else { echo '文件不存在'; } |
(2)get_headers取得服务器响应一个 HTTP 请求所发送的所有标头,效率较低,你可以测试下。
代码如下 | 复制代码 |
$url = 'http://www.111cn.net /img/qrcode_for_phpddt.JPG'; |
(3)file_get_contents()函数
代码如下 | 复制代码 |
$opts = array( 'http'=>array( 'timeout'=>3, ) ); $context = stream_context_create($opts); $resource = @file_get_contents('http://www.111cn.net /img/qrcode_for_phpddt.JPG', false, $context); if($resource) { echo '文件存在'; } else { echo '文件不存在'; } |
参考资料:fopen函数用法
参数 | 描述 |
---|---|
filename | 必需。规定要打开的文件或 URL。 |
mode | 必需。规定要求到该文件/流的访问类型。可能的值见下表。 |
include_path | 可选。如果也需要在 include_path 中检索文件的话,可以将该参数设为 1 或 TRUE。 |
context | 可选。规定文件句柄的环境。Context 是可以修改流的行为的一套选项。 |
mode 参数的可能的值
mode | 说明 |
---|---|
"r" | 只读方式打开,将文件指针指向文件头。 |
"r+" | 读写方式打开,将文件指针指向文件头。 |
"w" | 写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 |
"w+" | 读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 |
"a" | 写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。 |
"a+" | 读写方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。 |
"x" |
创建并以写入方式打开,将文件指针指向文件头。如果文件已存在,则 fopen() 调用失败并返回 FALSE,并生成一条 E_WARNING 级别的错误信息。如果文件不存在则尝试创建之。 这和给底层的 open(2) 系统调用指定 O_EXCL|O_CREAT 标记是等价的。 此选项被 PHP 4.3.2 以及以后的版本所支持,仅能用于本地文件。 |
"x+" |
创建并以读写方式打开,将文件指针指向文件头。如果文件已存在,则 fopen() 调用失败并返回 FALSE,并生成一条 E_WARNING 级别的错误信息。如果文件不存在则尝试创建之。 这和给底层的 open(2) 系统调用指定 O_EXCL|O_CREAT 标记是等价的。 此选项被 PHP 4.3.2 以及以后的版本所支持,仅能用于本地文件 |
当我们使用phpMyAdmin导入备份的数据库文件时,默认只能上传小于2M的文件。但是通常我们的数据库备份文件是大于2M的,怎么办呢?其实我们只需修改一下php.ini文件中的一个参数即可。
解决办法一,有服务器修改权限
以使用USBWebserver搭建的WAMP环境为例,php.ini文件存在于两个地方:USBWebserversettings和USBWebserver 8php。
编辑php.ini,在其中找到:
代码如下 | 复制代码 |
upload_max_filesize = 2M |
把2M增加到20M或更大的数值即可。
保存文件,最后重启USBWebserver,或者说重新运行Mysql,就可以发现最大限制已经增大为……
慢着,竟然不是20M,而是8M。如图:
三好公民也不知道是什么原因,反正暂时够用就行了。有知道的,请给三好公民讲解一下,谢谢!
解决方法二,如果没有服务器修改权限我们只要另想办法了