Can't connect to sql with php!?

Discussion in 'HTML / PHP / JavaScript / CSS' started by Hud, Sep 27, 2008.

  1. Hud

    Hud

    Hi,
    I can't get my code to connect to the SQL Server 2005 database. My code is very simple:
    <?php
    $ConnString='DRIVER={SQL Server};SERVER=sql2k512.discountasp.net;DATABASE=SQL2005_etc';
    $DB_User='SQL2005_etc_user';
    $DB_Passwd='PASSWORD';
    $Connect = odbc_connect($ConnString, $DB_User, $DB_Passwd) or die ('Unable to connect to database');

    if($Connect){
    echo 'yay';
    }
    ?>

    Every time I try to go to that page, it just says:
    Warning: odbc_connect() [function.odbc-connect]: SQL error: [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded, SQL state IM002 in SQLConnect in /Library/WebServer/Documents/hudpro/test/test_connect.php on line 5
    Unable to connect to database


    Any help would be appreciated. I'm completely stuck and have an approaching deadline! Thanks!
     
  2. If you find the answer let me know. I've been trying to connect for weeks and am very frustrated.


    I am trying it this way.


    <?php



    $dbhost = 'localhost';


    $dbuser = 'sql2005_513285_database_user';


    $dbpass = '********';


    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die


    ('Error connecting to mysql');


    $dbname = 'sql2005_513285_database';


    mysql_select_db($dbname);


    etc.........
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    Your code should work fine. Can you message me your account? I'll check the server and make sure it is setup correctly.
     
  4. Hi,
    I don't mess with PHP at all but I wanted to at least locate some sort of help.
    In the link below there are a ton of user posts concerning PHP and SQL Server connections.
    http://us2.php.net/function.mssql-connect
     
  5. Hi everyone,

    I am having the same problem, cannot connect PHP to MS SQL server. It does not give an error, it just stops execution after i call the mssql_connect() function.
    I will email my account details to you bruce, please have a look.
     
  6. Bruce

    Bruce DiscountASP.NET Staff

    if you still have problem, try create a ticket as well.
     
  7. Hi Bruce,

    I still have the same problem. Did you do anything on my server to help?

    I had already created a ticket yesterday, they replied back that it is a programming issue and they cannot help. They asked me to post in this forum and they closed the ticket!
    I will create a new ticket again but I think they will close it again.

    I checked my phpinfo() and there is no mssql module listed. i brought that to their attention but they still said it is not in their domain. Is there a way i can change my php.ini file? I think i just need to add the mssql support there.

    Where do I go from here?

    Appreciate all your help. Incidentally i have another website to put up with PHP and MSSQL but I am worried to encounter the same problem all over again.

    Thanks,
    Philip
     
  8. Bruce

    Bruce DiscountASP.NET Staff

    mssql module is NOT installed. You'll have to use odbc to connect to SQL.

    PHP is kinda lame as far as connecting to SQL. mssql module uses the SQL Enterprise manager binary which means we have to install SQL on the web server (NOT TOO Smart..)
     
  9. Hi Bruce,

    You are absolutely correct. I used ODBC and it worked fine. Raymond pointed me to the same!
    Its working fine and I already booked one more website with you!

    Thanks a ton, this has been great.

    Philip
     
  10. Bruce
    It's been awhile since this message. I tried another direction without PHP and wasted more time. Is this the account information you need e:\web\garagesale2\htdocs garagesaleswizard.com ?
    Let me know whatever you need. I am about to give up.
     
  11. Hi everyone,

    I'm having a similar problem. I'm using an MSSQL 2008 database and trying to connect via DSNless ODBC with a PHP app. My connection string is:

    DRIVER={SQL Server};SERVER=sql2k801.discountasp.net;DATABASE=SQL2008_etc

    I know MSSQL 2008 is supposed to use a different driver string - "SQL Server Native Client 10.0" - but that doesn't work and this does. Odbc_connect returns a resource ID.

    Then when I try to query, it doesn't work. I've tried queries that work in Studio accessed with the same account, and "SELECT 'string' " queries. My odbc_exec returns FALSE, and yes I'm specifying the connection resource. odbc_errormsg returns NULL after this.

    Any ideas?
     
  12. Sorry, my mistake, I got it working. The above format for connection strings works fine with MSSQL2008 databases.
     

Share This Page