2010-02-26 1 views
1
<html> 
    <head> 
     <title>Connecting </title> 
    </head> 
    <body> 
     <?php 
    $host = "*.*.*.*"; 
$username = "xxx"; 
$password = "xxx"; 
$db_name = "xxx"; 

    $db = mssql_connect($host, $username,$password) 
    or die("Couldn't Connect"); 
$selected = mssql_select_db($db_name, $db) 
or die("Couldn't open database"); 

?> 
    </body> 
</html> 

Мое сообщение об ошибке:Подключение к SQL Server в Php - Удлинитель Err

Fatal error: Call to undefined function mssql_connect() in C:\wamp\www\php\dbase.php on line 12

Я использую WampServer 2,0 на Php 5.3.0

Когда я проверяю расширения, php_mssql проверяется , Я также проверил файл php.ini, чтобы убедиться, что он не закомментирован.

У меня есть файл dbase.php, сохраненный в C: \ wamp \ www \ php. Я попытался остановить обслуживание, закрыть все и снова запустить его. Я знаю, что проблема заключается в том, что файл расширения не включен каким-либо образом.

Ниже приведено копирование из файла php.ini. Примечание. Я сделал все http =/http, чтобы избежать публикации ссылок.

;;;;;;;;;;;;;;;;;;;;;;;;; ; Paths and Directories ; ;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2" ;include_path = ".:/php/includes" ; Windows: "\path1;\path2" include_path = "C:\wamp\bin\php\php5.3.0\ext" ; ; PHP's default setting for include_path is ".;/path/to/php/pear" ; /http://php.net/include-path

; The root of the PHP pages, used only if nonempty. ; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root ; if you are running php as a CGI under any web server (other than IIS) ; see documentation for security issues. The alternate is to use the ; cgi.force_redirect configuration below ;/http://php.net/doc-root doc_root =

; The directory under which PHP opens the script using /~username used only ; if nonempty. ; /http://php.net/user-dir user_dir =

; Directory in which the loadable extensions (modules) reside. ; /http://php.net/extension-dir ; extension_dir = "./" ; On windows: ; extension_dir = "ext" extension_dir = "c:/wamp/bin/php/php5.3.0/ext/"

; Whether or not to enable the dl() function. The dl() function does NOT work ; properly in multithreaded servers, such as IIS or Zeus, and is automatically ; disabled on them. ; /http://php.net/enable-dl enable_dl = Off

; cgi.force_redirect is necessary to provide security running PHP as a CGI under ; most web servers. Left undefined, PHP turns this on by default. You can ; turn it off here AT YOUR OWN RISK ; You CAN safely turn this off for IIS, in fact, you MUST. ; /http://php.net/cgi.force-redirect ;cgi.force_redirect = 1

; if cgi.nph is enabled it will force cgi to always sent Status: 200 with ; every request. PHP's default behavior is to disable this feature. ;cgi.nph = 1

; if cgi.force_redirect is turned on, and you are not running under Apache or Netscape ; (iPlanet) web servers, you MAY need to set an environment variable name that PHP ; will look for to know it is OK to continue execution. Setting this variable MAY ; cause security issues, KNOW WHAT YOU ARE DOING FIRST. ; /http://php.net/cgi.redirect-status-env ;cgi.redirect_status_env = ;

; cgi.fix_pathinfo provides real PATH_INFO/PATH_TRANSLATED support for CGI. PHP's ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok ; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting ; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting ; of zero causes PHP to behave as before. Default is 1. You should fix your scripts ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED. ; /http://php.net/cgi.fix-pathinfo ;cgi.fix_pathinfo=1

; FastCGI under IIS (on WINNT based OS) supports the ability to impersonate ; security tokens of the calling client. This allows IIS to define the ; security context that the request runs under. mod_fastcgi under Apache ; does not currently support this feature (03/17/2002) ; Set to 1 if running under IIS. Default is zero. ; /http://php.net/fastcgi.impersonate ;fastcgi.impersonate = 1;

; Disable logging through FastCGI connection. PHP's default behavior is to enable ; this feature. ;fastcgi.logging = 0

; cgi.rfc2616_headers configuration option tells PHP what type of headers to ; use when sending HTTP response code. If it's set 0 PHP sends Status: header that ; is supported by Apache. When this option is set to 1 PHP will send ; RFC2616 compliant header. ; Default is zero. ; /http://php.net/cgi.rfc2616-headers ;cgi.rfc2616_headers = 0

;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads. ;/http://php.net/file-uploads file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; /http://php.net/upload-tmp-dir upload_tmp_dir = "c:/wamp/tmp"

; Maximum allowed size for uploaded files. ; /http://php.net/upload-max-filesize upload_max_filesize = 2M

Кроме того, мой файл php.ini сохраняется в C: \ WAMP \ Bin \ Apache \ Apache2.2.11 \ бин

ответ

0

Может быть, PHP использует другой INI файл как C: \ Windows \ php.ini, это случилось со мной в прошлом :)

1

У меня была такая же проблема, и решение довольно простое. Драйвер по умолчанию в PHP 5.3 для MS SQL Server больше не работает в Windows. Microsoft выпустила драйвер, который вы можете использовать. Водитель поставляется с документацией.

Вот ссылка, где можно найти скачать: http://sqlsrvphp.codeplex.com/

Вот ссылка, где вы можете найти некоторые документы: http://msdn.microsoft.com/en-us/library/cc296172(SQL.90).aspx

0

Ну так как вы используете PHP 5.3 будет не больше смысла использовать объекты PDO? Как так:

<?php 

class DatabaseConn { 

    static function createNewMySQLConnection() { 

     try { 
      $conn = new PDO("mysql:dbname=" . MYSQL_DB_DATA . "; host=" . MYSQL_DB_HOST, MYSQL_DB_USER, MYSQL_DB_PASS); 
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     } catch (PDOException $e) { 
      $x = new MyException("Failed to connect to db: " . $e->getMessage()); 
      $x->errorMessage(); 
      return null; 
     } 

     $conn->beginTransaction(); 

     return $conn; 
    } 

    static function createNewPgSQLConnection() { 

     try { 
      $conn = new PDO("pgsql:dbname=" . PGSQL_DB_DATA . "; host=" . PGSQL_DB_HOST, PGSQL_DB_USER, PGSQL_DB_PASS); 
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     } catch (PDOException $e) { 
      $x = new MyException("Failed to connect to db: " . $e->getMessage()); 
      $x->errorMessage(); 
      return null; 
     } 

     $conn->beginTransaction(); 

     return $conn; 
    } 

    static function createNewMsSQLConnection() { 

     try { 
      $conn = new PDO("dblib:dbname=" . MSSQL_DB_DATA . "; host=" . MSSQL_DB_HOST, MSSQL_DB_USER, MSSQL_DB_PASS); 
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     } catch (PDOException $e) { 
      $x = new MyException("Failed to connect to db: " . $e->getMessage()); 
      $x->errorMessage(); 
      return null; 
     } 

     $conn->beginTransaction(); 

     return $conn; 
    } 

    static function runExecute($conn, $query) { 

     try { 

      $stmt = $conn->prepare($query->sql); 
      if (isset($query->input) && !is_null($query->input)) { 
       $stmt->execute($query->input); 
       return true; 
      } else { 
       $stmt->execute(); 
       return true; 
      } 
     } catch (PDOException $e) { 

      if (isset($query->input)) { 

       $inputs = ""; 
       foreach ($query->input as $i) { 
        $inputs .= "'" . $i . "' "; 
       } 
       $msg = "$query->sql with input(s) $inputs. statement failed, rolling back: " . $e->getMessage(); 
      } else { 
       $msg = "$query->sql . statement failed, rolling back: " . $e->getMessage(); 
      } 
      $x = new MyException($msg); 
      $x->errorMessage(); 
     } 
     return false; 
    } 

    static function runPreparedQuery($conn, $query) { 

     $results = null; 
     try { 
      $stmt = $conn->prepare($query->sql); 
      if (isset($query->input) && !is_null($query->input)) { 
       $stmt->execute($query->input); 
      } else { 
       $stmt->execute(); 
      } 
      $results = $stmt->fetchAll(); 
     } catch (PDOException $e) { 

      if (isset($query->input)) { 

       $inputs = ""; 
       foreach ($query->input as $i) { 
        $inputs .= "'" . $i . "' "; 
       } 
       $msg = "$query->sql with input(s) $inputs. statement failed, rolling back: " . $e->getMessage(); 
      } else { 

       $msg = "$query->sql . statement failed, rolling back: " . $e->getMessage(); 
      } 

      $x = new MyException($msg); 
      $x->errorMessage(); 

      return null; 
     } 

     return $results; 
    } 

    static function getLastInsertId($conn) { 
     return $conn->lastInsertId(); 
    } 

    static function closeConn($conn, $commit) { 

     if ($commit) { 
      $conn->commit(); 
     } else { 
      $conn->rollBack(); 
     } 

     $conn = null; 
    } 

} 
?> 

Это не идеально, но это работает для меня