2010-02-26 7 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> 

Mon message d'erreur est:Connexion à SQL Server dans Php - Extension Err

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

J'utilise 2.0 WampServer sur Php 5.3.0

Quand je vérifie les extensions, php_mssql est cochée . J'ai également vérifié le fichier php.ini pour m'assurer qu'il n'est pas commenté.

J'ai mon fichier dbase.php enregistré dans C: \ wamp \ www \ php. J'ai essayé d'arrêter le service, de tout fermer et de le redémarrer. Je sais que le problème est que le fichier d'extension n'est pas inclus d'une manière ou d'une autre.

Le texte ci-dessous est copié de mon fichier php.ini. note J'ai fait tout http =/http pour éviter de publier des liens.

;;;;;;;;;;;;;;;;;;;;;;;;; ; 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

En outre, mon fichier php.ini est enregistré dans: C: \ wamp \ bin \ apache \ Apache2.2.11 \ bin

Répondre

0

Peut-être que php utilise un autre fichier ini comme C: \ windows \ php.ini, il m'arrive dans le passé :)

0

Eh bien, puisque vous utilisez PHP 5.3 serait-il pas plus logique de utiliser les objets PDO? Comme si:

<?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; 
    } 

} 
?> 

Ce n'est pas parfait, mais ça marche pour moi