call to undefined function mssql_connect()

Discussion in 'PHP' started by rhodarose, Sep 20, 2010.

  1. #1
    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:
    
    <?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');
    			}
    		}
    ?> 
    
    PHP:
    call to undefined function mssql_connect()

    --------------------------------------------------------------------------------

    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:

    PHP Code:
    <?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');
    }
    }
    ?>
    i already enable extension mssql in php.ini
     
    rhodarose, Sep 20, 2010 IP
  2. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    First you need to check if your MS SQL Server could be connected from other host.
    Usually i have to configure the MS SQL server so it can be connected from the client.
    Enable TCP/IP and bla bla... i forgot what i did.
    But please test your MS SQL can be connected from C# or ASP.NET.
    If connected then you should find what is your PHP version.
    Looks like PHP 5.2.0 have bugs to connect to MS SQL:
    http://bugs.php.net/bug.php?id=40034
    Then the last thing, please check if MSSQL driver installed in your PHP.
    PHP connect to MS SQL server with ODBC, please check of ODBC driver is installed.
    See this for reference: http://www.easysoft.com/developer/languages/php/sql_server_unix_tutorial.html
     
    ivan.kristianto, Sep 20, 2010 IP
  3. rhodarose

    rhodarose Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    By the way i use Windows Server 2003, IIS, php 4.3.4,and SQL Server 2005 Express
    i configure already the php.ini for mssql.
    I also check if i have the php_mssql.dll in my extension folder and i have it.
    What do you mean other host?

    After i configure my php.ini still i cannot connect to sql.
     
    rhodarose, Sep 21, 2010 IP
  4. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    ivan.kristianto, Sep 21, 2010 IP
  5. rhodarose

    rhodarose Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i have ntwdblib.dll in my extension folder
    MDAC is for what purpose?
     
    rhodarose, Sep 21, 2010 IP
  6. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    MDAC will provide the ODBC driver, need by PHP to connect to MS SQL
     
    ivan.kristianto, Sep 21, 2010 IP
  7. rhodarose

    rhodarose Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok thank you..i will find a installer of MDAC
     
    rhodarose, Sep 21, 2010 IP
  8. ashishkg

    ashishkg Active Member

    Messages:
    233
    Likes Received:
    8
    Best Answers:
    3
    Trophy Points:
    68
    #8
    i Thing it will work now.
     
    ashishkg, Sep 21, 2010 IP
  9. rhodarose

    rhodarose Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    :(It does not work again
     
    rhodarose, Sep 21, 2010 IP
  10. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #10
    how about use odbc_connect() instead of mssql_connect()?
     
    ivan.kristianto, Sep 21, 2010 IP
  11. rhodarose

    rhodarose Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    YOU mean i enable also the odbc_connect in php.ini?
     
    rhodarose, Sep 21, 2010 IP
  12. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #12
    ivan.kristianto, Sep 21, 2010 IP
  13. asdirc

    asdirc Active Member

    Messages:
    275
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
  14. zeroecko

    zeroecko Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Look at your phpinfo() function...if you don't have one, create it.

    <?
    phpinfo();
    ?>

    save it as info.php or phpinfo.php, then call it from the browser.

    Near the top, you will see 2 lines in the table:


    Configuration File (php.ini) Path C:\WINDOWS
    Loaded Configuration File C:\PHP\php.ini


    If the Configuration File (php.ini) Path is C:\WINDOWS, simply copy ntwdblib.dll from c:\php to c:\windows.

    That should do it (as long as the Loaded Configuration File is the one that you removed the ";" from extension=php_mssql.dll

    Let me know if that doesn't help you.
     
    zeroecko, Oct 21, 2010 IP
  15. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    you must not have enabled the php_mssql.dll extenstion from php.ini
     
    xpertdev, Oct 21, 2010 IP
  16. zeroecko

    zeroecko Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    He said that he did enable it, but a common problem I see is the configuration file path is set to C:\WINDOWS, which means that "ntwdblib.dll", which is requried for mssql.dll to work must be in that path. This is the same for mysql.dll and libmysql.dll.

    Hope this helps.
     
    zeroecko, Oct 21, 2010 IP