使用php连接到microsoft sql server

时间:2015-06-18 04:25:39

标签: php sql-server

我正在尝试使用php连接到mssql服务器。 sql server在网络中的另一台机器上,我在我的机器上安装了XAMPP。我的服务器上没有安装microsoft sql。

我已经下载了PHP的sqlsrv驱动程序,然后在我的php.ini文件中添加了扩展名php_pdo_sqlsrv_55_ts.dll在windows扩展名下。

在我的XAMPP安装的php\ext\文件夹中添加了phpinfo();文件。

重新启动apache PDO support enabled PDO drivers mysql, sqlite, sqlsrv 后显示已启用sqlsrv驱动程序

<?php
$serverName = "192.168.100.102, 1433";
$connectionInfo = array( "Database"=>"ATP", "UID"=>"raihan", "PWD"=>"temp123#");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

这是我的代码

    public boolean onTouchEvent(MotionEvent ev) {

    initialise boolean actionDownFlag = false;

    if(ev.getAction() == MotionEvent.ACTION_DOWN) {
        // the new image position became where you touched
        x = (int) ev.getX();
        y = (int) ev.getY();


    // if statement to detect where user presses down        
    if(actionDownFlag){

        catcher.moveDown();
    }
        // redraw the image at the new position
        Draw.this.invalidate();
    }
    return true;
}

    public void moveDown(){

        posX -= //WhereEver you want to move the position (-5);
    }

但在执行时我收到此错误

  

致命错误:调用未定义的函数sqlsrv_connect()   第4行的D:\ xampp \ htdocs \ database \ index.php

为什么会出现这个错误?我如何使用php连接到mssql服务器?

1 个答案:

答案 0 :(得分:2)

php\etc\听起来像错误的文件夹,请尝试放入php\ext\文件夹

注意extension=php_pdo_sqlsrv_55_ts.dll由PDO类

使用
  1. 转到https://www.microsoft.com/en-us/download/details.aspx?id=20098
  2. 选择您的PHP版本下载:

    • 如果使用SQLSRV30.EXE
    • ,请选择SQL Server 2005
    • 如果使用SQLSRV31.EXE
    • ,请选择SQLSRV31.EXESQL Server 2008
  3. 下载后,提取dll
  4. 如果你使用php与ThreadSafe(apache2handler - 更有可能)复制php_sqlsrv_55_ts.dll fot ext文件夹
  5. 使用sqlsrv在php.ini extension=php_sqlsrv_55_ts.dll中取消注释(或放置)此行(或extension=php_sqlsrv_55_nts.dll为无线程安全)

相关问题