www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: call to undefined function mssql_connect()

  1. #1
    Join Date
    Aug 2010
    Posts
    212

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

  2. #2
    Join Date
    Sep 2010
    Posts
    62
    Does php_info() show the extension as successfully loaded? If you look at your php.ini file, is the line for the mssql extension commented out?

  3. #3
    Join Date
    Aug 2010
    Posts
    212
    Quote Originally Posted by qjensen View Post
    Does php_info() show the extension as successfully loaded? If you look at your php.ini file, is the line for the mssql extension commented out?
    what do you mean php_info()?

    i commented out the mssql extension but still the my webpage did not appear and the error is still there

  4. #4
    Join Date
    Sep 2010
    Posts
    62
    create a simple php page and put one line in it

    Code:
    <?php
      php_info()
    ?>
    And look at the output to see if the module is reported as installed.

    I asked if the line was commented out because in some installs it ends up commented out by default. If the line is commented out, the module won't be loaded, so you want to make sure it is NOT commented out.

  5. #5
    Join Date
    Aug 2010
    Posts
    212
    Quote Originally Posted by qjensen View Post
    create a simple php page and put one line in it

    Code:
    <?php
      php_info()
    ?>
    And look at the output to see if the module is reported as installed.

    I asked if the line was commented out because in some installs it ends up commented out by default. If the line is commented out, the module won't be loaded, so you want to make sure it is NOT commented out.
    the extension mssql has ; and i delete it.
    and i try the php_info()
    but the result is the page cannot be found.

  6. #6
    Join Date
    Mar 2009
    Posts
    452
    it looks mssql extention is not configured correctly....

  7. #7
    Join Date
    Aug 2010
    Posts
    212
    Quote Originally Posted by ZABI View Post
    it looks mssql extention is not configured correctly....
    How can i configure it correctly?

  8. #8
    Join Date
    Sep 2010
    Posts
    62
    Did you restart apache after uncommenting the mssql extension?

  9. #9
    Join Date
    Aug 2010
    Posts
    212
    I'm not using apache. I used IIS, after i uncommented the mssql extension i restart my computer but still the error is still there.

  10. #10
    Join Date
    Sep 2010
    Posts
    62
    So we really need to see the output of php_info.

    Create a page in the same directory as the other php files you are working on. Call it info.php. In that file just put
    Code:
    <?php
      php_info()
    ?>
    The go to your browser and go to that page. If you get a message that the page is not found, you either put the page in the wrong place or pointed your browser at the wrong place.

    You should get a bunch of output that will give you information about your php configuration.

  11. #11
    Join Date
    Aug 2010
    Posts
    212
    Quote Originally Posted by qjensen View Post
    So we really need to see the output of php_info.

    Create a page in the same directory as the other php files you are working on. Call it info.php. In that file just put
    Code:
    <?php
      php_info()
    ?>
    The go to your browser and go to that page. If you get a message that the page is not found, you either put the page in the wrong place or pointed your browser at the wrong place.

    You should get a bunch of output that will give you information about your php configuration.
    I'm sure wiht the location of phpinfo but still the page cannot be displayed.
    Is it theres a problem with the php version that i have because it is not compatible with mssql?

  12. #12
    Join Date
    Aug 2010
    Posts
    212
    Quote Originally Posted by rhodarose View Post
    I'm sure wiht the location of phpinfo but still the page cannot be displayed.
    Is it theres a problem with the php version that i have because it is not compatible with mssql?
    Actually, now I only test my webpage in a computer that I create as a server. And also Iím not too familiar in a server. Now I created a database in SQL Server 2005 Express and some of information I will share is:

    Server Type: Database Engine
    Server name: ComputerName\SQLEXPRESS
    Authentication: Windows Authentication
    Username: NETBIOS NAME\Administrator [hide]
    Password: [hide]

    My problem is I cannot connect to my database using php and I don't know what username and password I should use if the Username: NETBIOS NAME\Administrator Password: [no password]

    This is my php 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"); 
    //} 


    $server "Computer Name\SQLEXPRESS";
    $user "NETBIOS\Administrator";
    $pass "";
    $db_name="dbase"

    //connection to database
    $dbhandle mssql_connect($server$user$pass) or die ("Cannot connect to Server");

    //mssql_connect($server, 'sa', 'pass') or die("Cannot connect to server"); 
    $selected mssql_select_db($db_name$dbhandle)or die("Cannot select DB");    


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

            
    $sql=mssql_query("SELECT `Department`, `Username` FROM `tbl_user` 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 don't know if what configuration i need to do to work my connection. I configured php.ini like:

    I uncommented the following:

    extension_dir = "C:\php\ext"
    extension=php_sqlsrv_52_ts_vc6.dll
    extension=php_bz2.dll
    extension=php_curl.dll
    extension=php_dba.dll
    extension=php_exif.dll
    extension=php_gd2.dll
    extension=php_gettext.dll

    mssql.allow_persistent=On
    mssql.max_persistent=-1
    mssql_max_links=-1
    mssql.min_error_severity=10
    mssql.compatibility_mode=Off
    mssql.connect_timeout=5
    mssql.timeout=60
    mssql.textlimit=4096
    mssql.textsize=4096
    mssql.batchsize=0
    mssql.datetimeconvert=On
    mssql.secure_connetion=Off

    FreeTDS default to 4096
    mssql.max_procs=25
    mssql.charset = "ISO-8859-1"

    After I commented out that in php.ini, I put all sqlsrv file in C:\php\ext and the ntwdlib.dll into C:\WINDOWS\system32. After that still when I run my webpage the error is still there. I have no idea how I can fix that error.


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

    I hope somebody can help or tell me what I should do.
    Thank you

  13. #13
    Join Date
    Oct 2010
    Posts
    2
    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.

  14. #14
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    Wow, this was a wacky thread.

    The correct command is "phpinfo();" without the underscore, with the () and although the semi-colon on the end isn't required if its the only command in the script, it's good habit to add it. How can something so easy result in so many comments!

    Secondly, for Windows web servers the extension needs to be enabled (uncommented) in php.ini, and then the web server needs to be restarted to pick up the change. It's that simple. Don't mess with the other MSSQL settings unless you know the extension is properly loaded, the PHP code is valid, but still errors and you know what you're doing. I mean to say things like "simply copy ntwdblib.dll from c:\php to c:\windows" might be necessary, but its rare these days.

    FYI -- You can also run "php -m" via command line in a command shell if a PHP CLI was installed and view the loaded modules that way, i.e. you'll see "MSSQL" included in the list. In Windows just run the command, in *nix type "which php" to get the path if it doesn't work the first time or you want to check to see if the CLI daemon exists.

    -jim
    Last edited by SrWebDeveloper; 10-21-2010 at 12:22 PM. Reason: fixed typo

  15. #15
    Join Date
    Oct 2010
    Posts
    2
    I know it might be rare to have it in a different location, but every time I have helped someone with this very issue, they had the extension = php_mssql.dll uncommented, they modified the correct php.ini, and the mssql (btw basically same issue with mysql) doesn't load. It was because the configuration file path was not to c:\php. The php.ini was loading correctly, but it did not see the required dll files to run what it needed, so it bypassed it.

    Again, it's rare, but it can happen. He seems to have done everything else right, so it could be that issue.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles