$conn=new COM('ADODB.Connection') or die('连接错误');
$myDSN="Provider=SQLNCLI.1;Persist Security Info=True;Data Source=localhost;User ID=sa;Password=sasa;Initial Catalog=db_php";
$conn->open($myDSN) or die('连接语句无效');$sql="select * from [username]";
$rs=$conn->execute($sql);
if($rs->eof()){
print('没有任何数据');}else{
while(!$rs->eof()){
echo $rs->fields[0]->value;
$rs->movenext();}}
上面代码出现  “链接语句无效”  什么原因 大家帮忙看下哈。

解决方案 »

  1.   

    PHP不懂,应该是连接字符串$myDSN的问题吧!
      

  2.   


    恩,我也是怀疑是 mydsn的问题,但是不知道这句有什么问题。
      

  3.   


    Provider=SQLNCLI.1;Persist Security Info=True;Data Source=localhost;User ID=sa;Password=sasa;Initial Catalog=db_php SQLNCLI 是指sql native client 驱动,为sqlserver2005协议
    Provider=SQLOLEDB.1是为sqlserver2000协议
    试一下
    Provider=SQLOLEDB.1
    Data Source=(localhost)
      

  4.   

    还是出现 这样的问题,连接语句无效,我的数据库是 sql server 2005 的。
      

  5.   


    --先试试CMD
    -->net start mssqlserver
      

  6.   


    我查看了下,好像根本就没有这个服务,
    net start mssqlserver提示 服务名无效。
      

  7.   

    这个服务在 控制面板 --管理工具  --服务 中。
    中mssql的服务!
    检查一下是否启动了?
    试一下
    Provider=SQLNCLI.1;Persist Security Info=false;Data Source=(localhost);User ID=sa;Password=sasa;Initial Catalog=db_php