SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Connecting to MS SQL from php

    I am trying to connect to an MS SQL database using the following PHP code:

    PHP Code:
    $hostname_conn_iShore "213.171.201.131";
    $database_conn_iShore "database_name";
    $username_conn_iShore "username";
    $password_conn_iShore "password";
    $conn_iShore mssql_connect($hostname_conn_iShore$username_conn_iShore$password_conn_iShore); 
    However, I am getting an Internal Server Error (500).

    Any ideas why?

  2. #2
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    500 means there was a PHP error. Can you post that error form your logs?

    It is likely that you gave 3 params instead of 4 (you missed the DB name)

    Also, putting "_iShore" at the end of var names is something I bet you will regret. Why not simply do:

    Code php:
    $db_con = mssql_connect("213.171.201.131", "database_name", "username", "password");
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    500 means there was a PHP error. Can you post that error form your logs?

    It is likely that you gave 3 params instead of 4 (you missed the DB name)

    Also, putting "_iShore" at the end of var names is something I bet you will regret. Why not simply do:

    Code php:
    $db_con = mssql_connect("213.171.201.131", "database_name", "username", "password");
    Tried adding the database name but got same error. Also, I cant post error logs as this is on a shared server.

  4. #4
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please refer - http://php.net/manual/en/function.mssql-connect.php

    i think you don't have to provide database name as the syntax say

    resource mssql_connect ([ string $servername [, string $username [, string $password [, bool $new_link ]]]] )

    Regards


Bookmarks

Posting Permissions

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