Results 1 to 13 of 13

Thread: PHP Script that connects with MS-SQL Database

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2013
    Location
    Spain
    Posts
    44

    PHP Script that connects with MS-SQL Database

    Hi everyone. I got a html webpage and I need to create a Database with users and passwords (typical). I've tried so many times to connect with the MSSQL database with a PHP Script without success... The MSSQL database is hosted in 1and1 servers (and the complete webpage). I've tried different codes but any worked right.

    A button in the html webpage executes the PHP Script, it executes right but the browser shows this error
    Code:
    Fatal error: Call to undefined function mssql_connect() in E:\kunden\homepages\13\d436936547\www\conec.php on line 2
    Does anyone know how to RIGHT connect with a MSSQL database with PHP Script.
    I've thought that the error could be in the server security from 1and1 or protected ports or something.
    Can anyone helpm me?

    Thanks.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: PHP Script that connects with MS-SQL Database

    Where are you running the script from?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Lively Member
    Join Date
    Apr 2011
    Posts
    75

    Re: PHP Script that connects with MS-SQL Database

    Try sqlsrv_connect using SQLSrv. Goggle for : mssql_connect sqlsrv_connect

    “mssql was dropped from PHP 5.3 distribution. Since the “php_mssql.dll” is no longer deployed with PHP 5.3, all calls to “mssql_” API are expected to fail."

    http://blogs.msdn.com/b/brian_swan/a...ce-part-1.aspx

    See here, but ignore the Yii stuff
    http://www.yiiframework.com/wiki/192...5-2008/#c10847
    Last edited by geek648; Feb 19th, 2013 at 01:07 PM.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2013
    Location
    Spain
    Posts
    44

    Re: PHP Script that connects with MS-SQL Database

    The script is run from an HTML page, when I click a button it does an action "action='script.php'".

    The script ("script.php") is hosted in an internet server with the HTML page that runs it.
    Last edited by corei7; Feb 19th, 2013 at 01:44 PM.

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2013
    Location
    Spain
    Posts
    44

    Re: PHP Script that connects with MS-SQL Database

    I'm sorry im kinda "noob" with databases, actually I've never used them before with webpages. What I need is a Webpage with a form or just a button to connect with a MSSQL Database in a HOSTING server, not in my server.

    What I pretend to do is test the conenction by pressing a Button on the HTML page hosted in the server.

    http://www.yiiframework.com/wiki/192...5-2008/#c10847

    That post teaches how to do it with a local server right? I need to install or change files, but I can't do it in a hosting server provided by 1and1. Help?

    Sorry if im too noob
    Thanks!

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: PHP Script that connects with MS-SQL Database

    That's why I was asking where the script is running at... I'm hosted by 1and1 as well... I have a MySQL database though, but even the SQL Server databases are hosted the same way... and that was is like this: The database servers are actually hosted INSIDE their network... they are NOT publicly visible, but hidden behind a firewall. This protects your data (and their servers) from outside attacks. So the ONLY way to access the database is from a webpage that is on THEIR network as well, in other words, they also host the script page that's trying to access the database.

    It's still not clear that your script is being hosted on their servers, or on another one... So you cannot have a web page that hosted by GoDaddy for instance accessing a database hosted by 1and1 ... at least not directly... there are ways around it. Sort of. The short of it is that you still have pages that access the database hosted by 1and1, and the response is in XML or some other format... then from your remote location, your pages there would simply use something like AJAX to request the data from the pages at 1and1 (rather than trying to hit the database directly)... they would then get the response back in the output.... and then parse is and use it... a sort of lite version of a webservice.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Lively Member
    Join Date
    Apr 2011
    Posts
    75

    Re: PHP Script that connects with MS-SQL Database

    SqlSrv connects to any SQL Server that can be reached.. there are some nuggets of helpfulness here -
    http://go4answers.webhost4life.com/E...ost-46406.aspx

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2013
    Location
    Spain
    Posts
    44

    Re: PHP Script that connects with MS-SQL Database

    I don't know if i understood. You mean the database data is saved in a XML document? In the hosting server there is a folder named "DB" which includes a XML document inside.

    Here is the code of the XML Document

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <handlers accessPolicy="Script" />
        </system.webServer>
    	
    	<connectionStrings>
      <add name="CustomerDataConnectionString" 
        connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind"
        providerName="System.Data.SqlClient" />
    </connectionStrings>
    
    </configuration>

  9. #9
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: PHP Script that connects with MS-SQL Database

    Quote Originally Posted by corei7 View Post
    I don't know if i understood. You mean the database data is saved in a XML document? In the hosting server there is a folder named "DB" which includes a XML document inside.

    Here is the code of the XML Document

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <handlers accessPolicy="Script" />
        </system.webServer>
    	
    	<connectionStrings>
      <add name="CustomerDataConnectionString" 
        connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind"
        providerName="System.Data.SqlClient" />
    </connectionStrings>
    
    </configuration>

    You need to start quoting who you're talking to... I have no idea if that's in reply to me or geek... but that aside... WHERE is the PHP code hosted? Is it being hosted on a 1and1 site? If not then THAT is the problem... you can only access databases on their network from within their own network... you CANNOT access it from any where else... not unless you also create a webservice that can then serve up the data for you... but that webservice then has to reside on server hosted by them... you WILL NOT be able to access it remotely. And it's still unclear at this point whether that is the case here or not.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2013
    Location
    Spain
    Posts
    44

    Re: PHP Script that connects with MS-SQL Database

    Quote Originally Posted by techgnome View Post
    You need to start quoting who you're talking to... I have no idea if that's in reply to me or geek... but that aside... WHERE is the PHP code hosted? Is it being hosted on a 1and1 site? If not then THAT is the problem... you can only access databases on their network from within their own network... you CANNOT access it from any where else... not unless you also create a webservice that can then serve up the data for you... but that webservice then has to reside on server hosted by them... you WILL NOT be able to access it remotely. And it's still unclear at this point whether that is the case here or not.

    -tg
    Sorry! I will reply Quoting from now on.

    The PHP Script is hosted on 1and1 servers. The full webpage is hosted there (HTML, CSS, PHP Scripts, JavaScript files...) The error on the browser shows the path:
    Code:
    Fatal error: Call to undefined function mssql_connect() in E:\kunden\homepages\13\d436936547\www\conec.php on line 7
    The PHP file is named "conec.php". When a button is pressed within the HTML page, it calls the PHP and executes it (PHP and HTML files are in the same folder hosted in 1and1 servers)

    Thanks for your patience, sorry

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2013
    Location
    Spain
    Posts
    44

    Re: PHP Script that connects with MS-SQL Database

    I've solved the problem! Thanks geek648, I found useful information in the post you told me, the error was in PHP script. Thanks to techgnome too for your patience!

    The code that worked for a connection with MSSQL using PHP Script ran from a Webpage is this:

    Code:
    <?php
    $serverName = "FQDN OF SERVER"; //serverName\instanceName
    $connectionInfo = array( "Database"=>"DATABASE", "UID"=>"DB USER", "PWD"=>"USER PWD");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
    if( $conn ) {
         echo "Connection established.<br />";
    }else{
         echo "Connection could not be established.<br />";
         die( print_r( sqlsrv_errors(), true));
    }
    ?>

  12. #12
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: PHP Script that connects with MS-SQL Database

    I don't care about the HTML (at least for now) ... the PHP is the source of the problem... in short, it sounds like the mssql module isn't loaded as part of the php package. Judging by the error message, it sounds like you're on a Windows hosting plan... in which case... I'm not sure what PHP modules are loaded...
    The intent (at least it used to be... unless things have changes) was that the Linux hosted sites would use PHP/MySQL, while the Windows hosted would allow ASP/ASP.NET/SQL server....

    You may want to talk to support at the host to find out what you do and don't have.

    -tg

    BLAH! That's what I get for taking too long to post... :P

    glad it's sorted though.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2013
    Location
    Spain
    Posts
    44

    Re: PHP Script that connects with MS-SQL Database

    Quote Originally Posted by techgnome View Post
    I don't care about the HTML (at least for now) ... the PHP is the source of the problem... in short, it sounds like the mssql module isn't loaded as part of the php package. Judging by the error message, it sounds like you're on a Windows hosting plan... in which case... I'm not sure what PHP modules are loaded...
    The intent (at least it used to be... unless things have changes) was that the Linux hosted sites would use PHP/MySQL, while the Windows hosted would allow ASP/ASP.NET/SQL server....

    You may want to talk to support at the host to find out what you do and don't have.

    -tg

    BLAH! That's what I get for taking too long to post... :P

    glad it's sorted though.

    -tg
    Thanks for using your time answering me!

Posting Permissions

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



Click Here to Expand Forum to Full Width