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

操作mssql的php代码

WBOY
发布: 2016-06-21 09:06:06
原创
1107 人浏览过

//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();
?>




相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板