1.

Solve : Call to undefined function mssql_connect()?

Answer»

Good day!

I change my database from sql yog to SQL Server 2005 Express so in php the connection is different, so now I am new in SQL Server 2005 Express. i edit my login page and I encountered error:

Fatal error: Call to undefined function mssql_connect() in C:\Inetpub\wwwroot\web_intranet\index.php on line 14

here is my code:
Code: [Select]<?php   
session_start();   
session_regenerate_id();   

if($_SESSION['loggedin']){   
//the USER is already logged in, lets redirect them to the other page   
    header("Location:company.php");   
}   

//require_once 'conn.php';     
$server = "PDOMAIN\MSFW";  
$db_name="dspi";   

mssql_connect($server) or die("Cannot connect to server");   
mssql_select_db("$db_name")or die("Cannot select DB");      


        $department = $_POST['department'];      
        $username = $_POST['username'];   

        $sql=mssql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mssql_min_error_severity());   
        $ct = mssql_num_rows($sql);   
        
        if($ct == 1) {   
// im guessing this means that the user is valid.   
$_SESSION['loggedin'] = true; // now that the user is valid we change the session value.   
            $row = mssql_fetch_assoc($sql);     
              
            //$_SESSION['username'] = $row['Username'] ;  
            //$_SESSION['department'] = $row['Department'];  
              
            $Departments=array('Accounting', 'Engineering', 'Finishing_Goods', 'HRAD', 'MIS', 'Packaging_and_Design', 'Production', 'Purchasing_Logistic', 'QA_and_Technical', 'Supply_Chain');  
              
            if (in_array($row['Department'], $Departments)){  
                    header ('Location:company.php');  
            }else{  
                    echo "Incorrect Username or Department";  
                    header ('Location:index.php');  
            }  
        }  
?>

By the way i use Windows Server 2003, IIS, php 5.2.14, and SQL Server 2005 Express
I already configure the php.ini to READ mssql.
I also check if I have ntwdblib.dll and i have it.
but still i cannot connect to sql.First, the "ntwdblib.dll" is outdated and was deprecated when SQL server 2000 was released. There is a SQL server 2005 driver for PHP:
SQL server 2005 driver for PHP


you can try changing  PHP from ISAPI MODE to FastCGI mode.

1. Install FastCGI for IIS6.
2. Modify your PHP install so it runs in FastCGI mode.


3.Open fcgiext.ini and add this to the end:

Code: [Select][Types]
php=PHP

[PHP]
ExePath=c:\PHP\php-cgi.exe
InstanceMaxRequests=10000
EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000


4) Add cgi.force_redirect=0 to the "; Default timeout for socket based streams (seconds)" section of PHP.ini.
5) MAKE sure your SQL database is set to Windows authentication mode and switch mssql.secure_connection in php.ini to on.
6) CREATE an SQL login for NT AUTHORITY\NETWORK SERVICE and give it the appropriate permissions to your database.
7) Reboot the server.


Source: Comments on the mssql_connect() function documentation, .



Discussion

No Comment Found