【问题标题】:Connecting php to MS SQL server 2008将 php 连接到 MS SQL Server 2008
【发布时间】:2015-08-06 05:57:45
【问题描述】:

我需要一个php和MS SQL的连接脚本: 在尝试以下但它不起作用

$server = 'MVEKELDG156\SQLEXPRESS'; $username   = 'EDUC.PWV.GOV.ZA\Mveke.L';    
$password   = 'password@'; $database    = 'SAMS_EMIS_Warehouses';       
if(!mysql_connect($server, $username, $password)) { exit('Error: could not 
establish database connection'); } if(!mysql_select_db($database)) { 
exit('Error: could not select the database'); }

【问题讨论】:

  • 我并不奇怪它没有工作,你忘了输入代码!
  • $server = 'MVEKELDG156\SQLEXPRESS'; $用户名 = 'EDUC.PWV.GOV.ZA\Mveke.L'; $password = '密码@'; $database = 'SAMS_EMIS_Warehouses'; if(!mysql_connect($server, $username, $password)) { exit('错误:无法建立数据库连接'); } if(!mysql_select_db($database)) { exit('错误:无法选择数据库'); }

标签: php sql sql-server-2008


【解决方案1】:

通过将extension=php_mssql.dll 添加到php.ini 来启用MSSQL 扩展。

要使这些函数正常工作,您必须使用 --with-mssql[=DIR] 编译 PHP,其中 DIR 是 FreeTDS 安装前缀。并且 FreeTDS 应该使用 --enable-msdblib 编译。

更多参考资料:

Installation

How to use PHP to connect to sql server

Connecting to an SQL Server Database with PHP

【讨论】:

    【解决方案2】:

    检查一下

    $myServer = "localhost";
    $myUser = "your_name";
    $myPass = "your_password";
    $myDB = "SAMS_EMIS_Warehouses";
    
    //connection to the database
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");
    
    //select a database to work with
    $selected = mssql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB
    

    来源How to connect to MS SQL Server database

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 1970-01-01
      • 2012-02-03
      相关资源
      最近更新 更多