首页 > 开发 > PHP > 正文

操作mssql的php代码

2024-05-04 22:59:36
字体:
来源:转载
供稿:网友
<style type="text/css">
input {font-family: "verdana";font-size: "11px";background-color: "#ffffff";height: "18px";border: "1px solid #666666";}
</style>
<?php
//mssql.php
$host="localhost";
$user="sa";
$password="";
$db="kao";error_reporting(7);
if(!$sql) $sql="select @@version";
echo "<form action=/"/" method=/"post/">";
echo "sql query: <input type=/"text/" value=/"".$sql."/" size=/"120/" name=/"sql/">";
echo "<input type=/"submit/" name=/"next/" value=/"提交/">";
echo "</form>";


$conn = new com("adodb.connection") or die("cannot start ado");
$conn->open("provider=sqloledb; data source=$host;
initial catalog=$db; user id=$user; password=$password");$rs = $conn->execute($sql);  
$num_columns = $rs->fields->count();
echo $num_columns . "/n";
for ($i=0; $i < $num_columns; $i++)
{
  $fld[$i] = $rs->fields($i);
}$rowcount = 0;
while (!$rs->eof)
{
  for ($i=0; $i < $num_columns; $i++)
  {
    echo $fld[$i]->value . "/t";
  }
  echo "/n";
  $rowcount++;        
  $rs->movenext();
}$rs->close();
$conn->close();$rs->release();
$conn->release();$rs = null;
$conn = null;
?>

php与access数据库连接的代码
<?
$dbc=new com("adodb.connection");
$dbc.open("driver=microsoft access driver (*.mdb);dbq=c:/member.mdb");
$rs=$dbc->execute("select * from tablename");
$i=0;
while (!$rs->eof){
$i+=1
$fld0=$rs->field(0);
$fld1=$rs->field(1);
....
echo "$fld0->value $fld1->value ....";
$rs->movenext();
}
$rs->close();
?>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表