操作mssql的php代码
摘自某论坛
<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();
?>