PMY-MS SQL databease connectivity help need?

Discussion in 'PHP' started by KingCobra, Sep 26, 2012.

  1. #1
    SORRY for mistake in title. It will be "PHP-MS SQL databease connectivity help need?"

    I am using
    Windows XP Sp-2
    XAMPP 1.7.4,
    PHP 5.3.5.

    I am trying to connect a MS SQL server database using PHP. But the php code giving me following error:

    Fatal error: Call to undefined function mssql_connect() in C:\Server\xampp\htdocs\db\connect.php on line 8


    
    <?php
    $myServer = "123.144.111.321";     // do I need port number here? what is my port ?
    $myUser = "test";
    $myPass = "test123";
    $myDB = "dbk";
    
    //connection to the database
    $dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");
    
    //select a database to work with
    $selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB");
    
    //declare the SQL statement that will query the database
    $query = "SELECT Company_Code, Company_Name ";
    $query .= "FROM [Status_Web] ";
    
    //execute the SQL query and return records
    $result = mssql_query($query);
    
    $numRows = mssql_num_rows($result);
    echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
    
    //display the results
    while($row = mssql_fetch_array($result))
    {
      echo "<li>" . $row["Company_Code"] . $row["Company_Name"] . "</li>";
    }
    //close the connection
    mssql_close($dbhandle);
    ?> 
    
    PHP:
    Would you please tell me how can I connect to the database?
    Thanks in advance.
     
    KingCobra, Sep 26, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Is this on a Windows install or linux? Assuming Windows, you most likely need to install the correct MSSQL dll's, and uncomment the mssql extension in your php.cnf/ini file. If you search around for XAMPP MSSQL you should be able to find instructions on how to get it working although it will likely take some messing around to get it working.

    If this is Linux, forget about it. Linux doesn't have native support for MSSQL and in my experience it's not worth the effort to try and hack it in using freetds, odbc, or another, unless you absolutely have to. We got it working a few years back and unless something has drastically changed, I would rather buy a new server or run a virtual windows install than trying to get Linux and MSSQL working again.
     
    jestep, Sep 26, 2012 IP
  3. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Dear jestep,

    Thank you for your reply. I am using Windows XP SP-2. How I will install correct MSSQL dll? I downloaded "php_mssql.dll" file from internet and placed ext folder. Then uncommitted "extension=php_mssql.dll". After that I restart Apache. Before start Apache it shows "php_mssql.dll" file not found message.
     
    KingCobra, Sep 27, 2012 IP
  4. Web Solutions

    Web Solutions Peon

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    0
    #4
    Either add it to PATH environment variable (you might need to restart your computer in order to apply those changes) or change the ext path in your php.ini file.
     
    Web Solutions, Sep 27, 2012 IP
  5. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Moderator, please correct the title of this post. It was my mistake and it will be -

    PHP-MS SQL databease connectivity help need?
     
    KingCobra, Sep 28, 2012 IP