遇到很大困难,望大家帮忙!!!(高分求解)

haoren7842 2006-08-28 09:18:39
我是一个php新手,现在有一段asp代码,要转成php,可是我根本没接触过asp,php也不是很熟,可是公司要的很急,现把asp发上来,望高手给些指点:

'书的概要信息
Sub GetBookInfo(UserName, PassWord, UUID, bWithFile, codec)
On Error Resume Next
set cnnDBNet = Server.CreateObject("ADODB.Connection")
dim strConn
strConn = Application("Read_EnglishFreeNet2005_CStr")
cnnDBNet.ConnectionString = strConn
cnnDBNet.Open()
set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM ex3_bookshelf WHERE BOOKLANGUAGE='"&Trim(codec)&"' ORDER BY orderno"
rs.Open strSQL, cnnDBNet, 1

if (rs.eof) then
response.write "Result=0"
rs.close()
set rs=nothing
cnnDBNet.close
set cnnDBNet=nothing
Exit Sub
end if

nRecords = rs.RecordCount
nFields = rs.Fields.Count


Response.BinaryWrite inttobinary(nRecords) '输出二进制数,和客户端软件通信
Response.BinaryWrite inttobinary(nFields+3)

For i=0 to (nFields -1)
Dim FieldName
FieldName = rs.Fields(i).Name
FieldName = Trim(FieldName)
Dim FiledNameLen
FieldNameLen = Len(FieldName)
Response.BinaryWrite Inttobinary(FieldNameLen)
Response.Write FieldName
Next

Response.BinaryWrite Inttobinary(11)
Response.Write "lessontitle"
Response.BinaryWrite Inttobinary(9)
Response.Write "lessongif"
Response.BinaryWrite Inttobinary(13)
Response.Write "lessontasknum"
Response.Flush

For i=0 to (nRecords - 1)
For j=0 to (nFields - 1)
Dim strLen
Dim str

If IsNull(rs(j)) Then
Response.BinaryWrite inttobinary(0)
Response.Flush
Else
str = Trim(rs(j))
If rs.Fields(j).Name = "BOOKCOVER" AND bWithFile then
Dim url
Dim fso, fl, flsize
Dim objStream, data
url = DataPath&"\"&rs("BOOKPATH")&rs(j)
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set fl=fso.getfile(url)
flsize=fl.size
Set fl=Nothing
Set fso=Nothing

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Mode = 16
objStream.Open
objStream.Type = 1
objStream.LoadFromFile url
data = objStream.Read

strLen = stringLen(str)
Response.BinaryWrite inttobinary(strLen+flsize+8)
Response.BinaryWrite inttobinary(strLen)
Response.Write str
Response.BinaryWrite inttobinary(flsize)
Response.BinaryWrite data
Response.Flush
Response.Clear()
objStream.Close
Set objStream = Nothing
Else
strLen = stringLen(str)
Response.BinaryWrite inttobinary(strLen)
Response.Write str
Response.Flush
End If
End If
Next

set rs2 = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT D_TITLE,D_TASKNUM FROM "&Trim(rs("BOOKTABLENAME"))&" ORDER BY D_RECNO"
rs2.Open strSQL, cnnDBNet, 1

Dim totalstr,totalstr2,totalstr3
totalstr = ""
totalstr2 = ""
totalstr3 = ""
For k=0 to (rs2.RecordCount-1)
totalstr = totalstr & Trim(rs2.Fields("D_TITLE")) & chr(13)+chr(10)
totalstr2 = totalstr2 & Trim(rs2.Fields("D_TASKNUM"))&".gif" & chr(13)+chr(10)
totalstr3 = totalstr3 & Trim(rs2.Fields("D_TASKNUM")) & chr(13)+chr(10)
rs2.MoveNext
Next

Response.BinaryWrite inttobinary(stringLen(totalstr))
Response.Write totalstr
Response.BinaryWrite inttobinary(stringLen(totalstr2))
Response.Write totalstr2
Response.BinaryWrite inttobinary(stringLen(totalstr3))
Response.Write totalstr3
Response.Flush
rs2.close()
set rs2 = nothing

rs.MoveNext
Next
Response.Write "Result=1"

rs.close()
set rs=nothing
cnnDBNet.close
set cnnDBNet=nothing

End Sub

主要是asp取记录那段,如何转化为php的程序!!!!多谢大家了
...全文
159 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
haoren7842 2006-08-28
  • 打赏
  • 举报
回复
呵呵,是呀,一共4个文件,很大一部分,唉,转的都头疼了,呵呵
多谢大家了,有没有高手愿意我把文件发过去,帮忙看看呀!!
呵呵!!
caotian2000 2006-08-28
  • 打赏
  • 举报
回复
单纯的转换肯定不行!大家没帮你看过别的文件呢!

就算看过了,这么一大篇,写也得写一阵呢!

看得头都大了
haoren7842 2006-08-28
  • 打赏
  • 举报
回复
多谢,上面的回复,这个代码肯定是和其他代码有关联的,我再仔细研究下逻辑吧,呵呵
还有没有高手帮忙呀!!
caotian2000 2006-08-28
  • 打赏
  • 举报
回复
唠叨大哥!那样行嘛?

你看数据库连接都不一样哦
xuzuning 2006-08-28
  • 打赏
  • 举报
回复
如果你依然是用在win32环境中,则直译即可
1、给变量加上$前导
2、给每句加上结束符“;”
3、形如
set cnnDBNet = Server.CreateObject("ADODB.Connection")
的改为形如
$cnnDBNet = new com("ADODB.Connection");
4、& 改为 .
5、对象成员连接符由“.”改为“->”

totalstr = totalstr & Trim(rs2.Fields("D_TITLE")) & chr(13)+chr(10)
改做
$totalstr = $totalstr . trim($rs2->Fields("D_TITLE")) . chr(13).chr(10);
keaizhong 2006-08-28
  • 打赏
  • 举报
回复
我想应该会有一些小问题,这个应该要你自己根据需要去改了。。
keaizhong 2006-08-28
  • 打赏
  • 举报
回复
<?
//??????
function GetBookInfo($UserName,$PassWord,$UUID,$bWithFile,$codec)
{
extract($GLOBALS);


// $cnnDBNet is of type "ADODB.Connection"
$strConn=$Application["Read_EnglishFreeNet2005_CStr"];
echo $strConn;
$a2p_connstr=;
$a2p_uid=strstr($a2p_connstr,'uid');
$a2p_uid=substr($d,strpos($d,'=')+1,strpos($d,';')-strpos($d,'=')-1);
$a2p_pwd=strstr($a2p_connstr,'pwd');
$a2p_pwd=substr($d,strpos($d,'=')+1,strpos($d,';')-strpos($d,'=')-1);
$a2p_database=strstr($a2p_connstr,'dsn');
$a2p_database=substr($d,strpos($d,'=')+1,strpos($d,';')-strpos($d,'=')-1);
$cnnDBNet=mysql_connect("localhost",$a2p_uid,$a2p_pwd);
mysql_select_db($a2p_database,$cnnDBNet);
// $rs is of type "ADODB.Recordset"
$strSQL="SELECT * FROM ex3_bookshelf WHERE BOOKLANGUAGE='".trim($codec)."' ORDER BY orderno";
$rs=mysql_query($strSQL);

if ((($rs==0)))
{

print "Result=0";

$rs=null;

mysql_close($cnnDBNet);
$cnnDBNet=null;

return $function_ret;

}


$nRecords=mysql_num_rows($rs_query);
$nFields=->$Count;


print $inttobinary[$nRecords];//??????,????????
print $inttobinary[$nFields+3];

for ($i=0; $i<=($nFields-1); $i=$i+1)
{
$FieldName=($i)->$Name;
$FieldName=trim($FieldName);
$FieldNameLen=strlen($FieldName);
print $Inttobinary[$FieldNameLen];
print $FieldName;

}


print $Inttobinary[11];
print "lessontitle";
print $Inttobinary[9];
print "lessongif";
print $Inttobinary[13];
print "lessontasknum";
flush();


for ($i=0; $i<=($nRecords-1); $i=$i+1)
{
for ($j=0; $j<=($nFields-1); $j=$j+1)
{

if (!isset($rs[$j]))
{

print $inttobinary[0];
flush();

}
else
{

$str=trim($rs[$j]);
if (($j)$Name=="BOOKCOVER" && $bWithFile)
{

$url=$DataPath."\\".$rs["BOOKPATH"].$rs[$j];
// $fso is of type "Scripting.FileSystemObject"
$fl=getfile($url) /* don't know how to convert this filesystem method */
$flsize=filesize($fl);
$fl=null;

$fso=null;


// $objStream is of type "ADODB.Stream"
$objStream->Mode=16;
$objStream->Open;
$objStream->Type=1;
$objStream->LoadFromFile$url;
$data=$objStream->Read;

$strLen=$stringLen[$str];
print $inttobinary[$strLen+$flsize+8];
print $inttobinary[$strLen];
print $str;
print $inttobinary[$flsize];
print $data;
flush();

ob_clean();

$objStream->Close;
$objStream=null;

}
else
{

$strLen=$stringLen[$str];
print $inttobinary[$strLen];
print $str;
flush();

}

}


}


// $rs2 is of type "ADODB.Recordset"
$strSQL="SELECT D_TITLE,D_TASKNUM FROM ".trim($rs["BOOKTABLENAME"])." ORDER BY D_RECNO";
$rs=mysql_query($strSQL);

$totalstr="";
$totalstr2="";
$totalstr3="";
for ($k=0; $k<=(mysql_num_rows($rs2_query)-1); $k=$k+1)
{
$totalstr=$totalstr.trim(("D_TITLE")).chr(13)+chr(10);
$totalstr2=$totalstr2.trim(("D_TASKNUM")).".gif".chr(13)+chr(10);
$totalstr3=$totalstr3.trim(("D_TASKNUM")).chr(13)+chr(10);
$rs2=mysql_fetch_array($rs2_query);


}


print $inttobinary[$stringLen[$totalstr]];
print $totalstr;
print $inttobinary[$stringLen[$totalstr2]];
print $totalstr2;
print $inttobinary[$stringLen[$totalstr3]];
print $totalstr3;
flush();


$rs2=null;


$rs=mysql_fetch_array($rs_query);


}

print "Result=1";


$rs=null;

mysql_close($cnnDBNet);
$cnnDBNet=null;


return $function_ret;
}
?>

帮你转了,不过能不能用就不知道了。。你试试。。
你这个代码应该和其它的代码有关联的。
haoren7842 2006-08-28
  • 打赏
  • 举报
回复
啊?还有这种软件呢?
高手帮忙呀!!!!
keaizhong 2006-08-28
  • 打赏
  • 举报
回复
对ASP不了解了,不过你可以寻找一个asp2php的软件进行转换的。
keaizhong 2006-08-28
  • 打赏
  • 举报
回复
楼主可不要偷懒啊,其实这些修改和查看地的过程中可以学到很多。
google一下asp2php你会找到那个软件的,然后自己转一下,再试试看。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧