Rumah >php教程 >php手册 >操作mssql的php代码

操作mssql的php代码

WBOY
WBOYasal
2016-06-21 09:06:061100semak imbas

//mssql.php
$host="localhost";
$user="sa";
$password="";
$db="kao";error_reporting(7);
if(!$sql) $sql="select @@VERSION";
echo "
";
echo "SQL Query: ";
echo "";
echo "
";


$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 {
  $fld[$i] = $rs->Fields($i);
}$rowcount = 0;
while (!$rs->EOF)
{
  for ($i=0; $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();
?>




Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn