Php SQL Server Bağlanma - Uzatma Err

3 Cevap php
<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>

Benim hata iletisi:

Ölümcül hata: satır 12 \ wamp \ www \ php \ dbase.php: C tanımsız işlev mssql_connect () Çağrı

Ben PHP 5.3.0 üzerinde WampServer 2.0 kullanıyorum

Ben uzantıları kontrol ettiğinizde, php_mssql İşaretli. Ben de onu emin yorumladı olmadığından emin olmak için php.ini dosyasını kontrol etti.

\ Wamp \ www \ php: Ben C kaydedilir benim dosya dbase.php var. Ben, hizmetin durdurulması her şeyi kapatma ve tekrar çalışıyor denedim. Ben sorunun uzantısı dosya bir şekilde dahil ediliyor olmadığını biliyorum.

Aşağıda benim php.ini dosyasında kopyalanır. Note I made all http = /http to avoid posting Links.

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

C: Ayrıca, benim php.ini dosyası kaydedilir \ wamp \ bin \ apache \ Apache2.2.11 \ bin

3 Cevap

Ben aynı sorun vardı ve çözümü oldukça basit. MS SQL Server için PHP 5.3 varsayılan sürücü Windows artık çalışmıyor. Microsoft kullanabileceğiniz bir sürücü yayımladı. Sürücü belgeleri ile birlikte geliyor.

http://sqlsrvphp.codeplex.com/: Burada indirmek bulabilirsiniz link

http://msdn.microsoft.com/en-us/library/cc296172(SQL.90).aspx: Burada bazı belgeleri bulabilirsiniz link

Belki php C gibi başka ini dosyası kullanarak: windows \ php.ini \, bu geçmişte bana ne oldu :)

PHP 5.3 kullanıyorsanız bu yana iyi değil PDO nesneleri kullanmak daha mantıklı olur? Şöyle:

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

}
?>

Mükemmel değil ama benim için çalışıyor