关于运行sql的问题??在线等待!高分赠送! 直接从文件中读出来赋值给一个字符串变量,再执行mysql_query有什么问题吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 刚刚好有个程序是导入sql文件的,不知你能不能用。每行对应一个sql语句.一行行读入然后执行就行。<?phprequire("../include/config.inc.php"); //定义数据库连接信息?><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="/css/css.css" type="text/css"></head><body bgcolor="#FFFFFF" text="#000000">总体进度:<table border=0 cellpadding=0 cellspacing=0 id=tab1 width=100%><tr align=right><td>10%</td><td>20%</td><td>30%</td><td>40%</td><td>50%</td><td>60%</td><td>70%</td><td>80%</td><td>90%</td><td>100%</td></tr></table><?phpset_time_limit(9999);echo "<font color=blue><b>开始准备导入数据,初始化中...</b></font><br>";flush();$fp=fopen($sqlfile,"r"); // 指定$sqlfile:sql文件if(!$fp) exit;while (!feof ($fp)) { $line[] = fgets($fp, 4096);}$j=0;$k=0;$count=count($line);echo "<font color=blue><b>开始导入...</b></font><br>";flush();for($i=0;$i<$count;$i++){ $sql=str_replace(";","",$line[$i]); $ret=mysql_query($sql); if(mysql_affected_rows()>0){ echo "<font color=green>".$sql."</font><br>"; } else echo "<font color=red>".$sql."</font><br>"; flush(); $j++; if($j%(floor($count/10)-1)==0){ echo "<script>document.all.tab1.rows[0].cells[$k].bgColor='#00FF00';</script>"; flush(); $k++; }}?><div align=center><a href=main.php>[返回]</a></div></body></html> 看看以前别人写的一个将数据库倒入文本文件,然后还原数据库的例子:http://www.csdn.net/Expert/TopicView1.asp?id=874030http://www.csdn.net/expert/topic/873/873963.xml?temp=.4158594 用file函数读入文本数据就行了,何必这么罗嗦 自己实现的小程序smarty+ob_start()失败 请问oci_bind_by_name的写法如何支持in语句查询? 诡异。SESSION 为什么无法全局取 php session_id 不停的变化 什么错误?Warning: getimagesize(): php_network_getaddresses: gethostbyname 请教一个关于英文字符串传递的问题 图片问题 显示apache运行了多长时间的php程序的再次讨论 如何隐藏真实的文件名? 一个有关虚拟目录的问题,请高手点拨 急,急,急,怎么在指定目录下新见一个文件。 执行sql的问题??在线等待!高分赠送!
每行对应一个sql语句.一行行读入然后执行就行。<?php
require("../include/config.inc.php"); //定义数据库连接信息
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="/css/css.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
总体进度:
<table border=0 cellpadding=0 cellspacing=0 id=tab1 width=100%>
<tr align=right><td>10%</td><td>20%</td><td>30%</td><td>40%</td><td>50%</td><td>60%</td><td>70%</td><td>80%</td><td>90%</td><td>100%</td></tr>
</table>
<?php
set_time_limit(9999);
echo "<font color=blue><b>开始准备导入数据,初始化中...</b></font><br>";
flush();
$fp=fopen($sqlfile,"r"); // 指定$sqlfile:sql文件
if(!$fp)
exit;
while (!feof ($fp)) {
$line[] = fgets($fp, 4096);
}
$j=0;
$k=0;
$count=count($line);
echo "<font color=blue><b>开始导入...</b></font><br>";
flush();
for($i=0;$i<$count;$i++){
$sql=str_replace(";","",$line[$i]);
$ret=mysql_query($sql);
if(mysql_affected_rows()>0){
echo "<font color=green>".$sql."</font><br>";
}
else
echo "<font color=red>".$sql."</font><br>";
flush();
$j++;
if($j%(floor($count/10)-1)==0){
echo "<script>document.all.tab1.rows[0].cells[$k].bgColor='#00FF00';</script>";
flush();
$k++;
}
}
?>
<div align=center>
<a href=main.php>[返回]</a>
</div>
</body>
</html>