请将下面的ASP代码片段改写成php代码,小弟初学php,但没学过ASP啊,请高手指点。
<%response.expires=-1sql="SELECT*FROMCUSTOMERSWHERECUSTOMERID="sql=sql&"'"&request.qu...
<%
response.expires=-1
sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & "'" & request.querystring("q") & "'"
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, conn
response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><em>" & x.name & "</em></td>")
response.write("<td>" & x.value & "</td></tr>")
next
rs.MoveNext
loop
response.write("</table>")
%> 展开
response.expires=-1
sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & "'" & request.querystring("q") & "'"
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, conn
response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><em>" & x.name & "</em></td>")
response.write("<td>" & x.value & "</td></tr>")
next
rs.MoveNext
loop
response.write("</table>")
%> 展开
2个回答
展开全部
看代码,应该是连接Access数据库的吧。
<?php
//response.expires=-1,这句是设置缓存的。php可以用header(),不写了
$sql = "SELECT * FROM CUSTOMERS WHERE CUSTOMERID=";
$sql .= "'".$_GET['q']."'";
$conn = new Com("ADODB.Connection);
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath("/db/northwind.mdb");
$conn->Open($connstr);
//-----------
$rs = new Com("ADODB.RecordSet");
$rs->Open($sql,$conn,1,1);
//或者:
$rs = $conn->Execute($sql);
//-------------
echo "<table>";
while (!$rs->EOF){
foreach ($rs->Fields as $x){
echo "<tr><td><em>".$x->name."</em></td>";
echo "<td>" . $x->value."</td></tr>";
}
$rs->MoveNext();
}
echo "</table>";
/*最后,最好把$rs关掉,以下内容跟你的代码没有关系,不过是一般写法。*/
$rs->close();
$conn->close();
$rs->release();
$conn->release();
$rs=null;
$conn=null;
?>
其实差不多的吧。就是换个语法罢了。
<?php
//response.expires=-1,这句是设置缓存的。php可以用header(),不写了
$sql = "SELECT * FROM CUSTOMERS WHERE CUSTOMERID=";
$sql .= "'".$_GET['q']."'";
$conn = new Com("ADODB.Connection);
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath("/db/northwind.mdb");
$conn->Open($connstr);
//-----------
$rs = new Com("ADODB.RecordSet");
$rs->Open($sql,$conn,1,1);
//或者:
$rs = $conn->Execute($sql);
//-------------
echo "<table>";
while (!$rs->EOF){
foreach ($rs->Fields as $x){
echo "<tr><td><em>".$x->name."</em></td>";
echo "<td>" . $x->value."</td></tr>";
}
$rs->MoveNext();
}
echo "</table>";
/*最后,最好把$rs关掉,以下内容跟你的代码没有关系,不过是一般写法。*/
$rs->close();
$conn->close();
$rs->release();
$conn->release();
$rs=null;
$conn=null;
?>
其实差不多的吧。就是换个语法罢了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询