php with sql server

Discussion in 'PHP' started by vbala2k5, Dec 26, 2011.

  1. #1
    Hi,

    i'm in new PHP. but i need to connect MSSQL WITH PHP. anyone help for how to connect php with sql server 2008. what are step to follow and what are the version need inform.

    Kindly give the details.
    Balaji V
     
    vbala2k5, Dec 26, 2011 IP
  2. amgadhs

    amgadhs Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The code below connects to a database and executes an SQL statement:

    
    $link = mssql_connect('.\SQLEXPRESS', 'sa', 'password');
    
    if (!$link) {
        die('Unable to connect to server!');
    }
    
    if (!mssql_select_db('database_name', $link)) {
        die('Unable to select database!');
    }
    
    $result = mssql_query('SELECT * FROM database_name');
    $row = mssql_fetch_array($result);
    
    echo $row[0]; //print the first field of the first record
    
    PHP:
     
    amgadhs, Dec 26, 2011 IP