Jump to content

Brian Swan

Members
  • Posts

    47
  • Joined

  • Last visited

    Never

Posts posted by Brian Swan

  1. jjmac-

     

    If you are moving to PHP5, I would suggest that you bite the bullet (as tough as it might be) and move to the sqlsrv driver (the SQL Server Driver for PHP). The old mssql driver is based on obsolete dblib technology (more about that here: http://blogs.msdn.com/b/brian_swan/archive/2010/03/08/mssql-vs-sqlsrv-what-s-the-difference-part-1.aspx). The good news is that the 2.0 release of the sqlsrv driver comes in two flavors: the SQLSRV driver (which is a "function-based" or "procedural" driver) and the PDO_SQLSRV driver (which supports PDO and is object-oriented). So, you shouldn't have to make the jump to using classes if you don't want to. The bad news is that there isn't an easy way (that I know of) to install PHP 5 with support for the old php_mssql.dll driver. Hopefully, this blog post will help convert to the sqlsrv driver: http://blogs.msdn.com/b/brian_swan/archive/2010/03/10/mssql-vs-sqlsrv-what-s-the-difference-part-2.aspx.

     

    On the question of CGI vs. Fast-CGI, definitely go with Fast-CGI (the CGI module spins up a new PHP process for every incoming request!). Performance with Fast-CGI is much better. One easy way to get this all set up is to use the Web Platform Installer (installs PHP, sqlsrv driver, SQL Server Express, etc...and configures everything). Check it out here: http://www.microsoft.com/web/downloads/platform.aspx. One drawback of the WPI is that it installs PHP 5.2.14, not PHP 5.3 (which has tons of Windows optimizations). The question of VC6 vs VC9 only comes into play (I think) if you are running PHP 5.3...in which case you should go for VC9. If you want to go with PHP 5.3, you'll have to install/configure it manually: http://php.net/manual/pl/install.windows.iis7.php.

     

    I hope that helps. Let me know if you have more questions.

     

    -Brian

  2. Heh...I was in the posting this reply just as you posted...

     

    I'm not sure I understand the scenario correctly, but I'll suggest code that is structured like this:

     

    if ($listoption == ALL)

    {

        Execute "SELECT * FROM details"

    }

    else

    {

        Execute "SELECT * FROM details WHERE otype = $listoption"

    }

     

    If that's not what you are looking for, post your relevant PHP code and describe in a bit more detail what isn't working...I'll look again.

     

    As a side note, I would avoid code that concatenates SQL with user input (but maybe you're just writing abbreviated code like I am and you're using parameterized queries in your real code). I have a blog post on this topic: http://blogs.msdn.com/b/brian_swan/archive/2010/03/04/what_2700_s-the-right-way-to-avoid-sql-injection-in-php-scripts_3f00_.aspx

     

    -Brian

  3. I think your query is returning 2 result sets: one for the "USE database" statement, and one for the "SELECT ..." statement. The first result set has no fields (obviously). Try calling sqlsrv_next_result($stmt) after you execute the query and before you start iterating through rows. Let me know how that works.

     

    -Brian

  4. Have you configured SQL Server to allow remote connections? If you have, can you get more detailed error info?

     

    BTW, since you are running PHP on Windows, I'd suggest you use the Microsoft-built driver (available here: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9 , or via the Web Platform Installer: http://www.microsoft.com/web/downloads/platform.aspx ). It does not rely on the depricated DBLib technology. If you are interested, more info here: http://blogs.msdn.com/b/brian_swan/archive/2010/03/08/mssql-vs-sqlsrv-what-s-the-difference-part-1.aspx and

    http://blogs.msdn.com/b/brian_swan/archive/2010/03/10/mssql-vs-sqlsrv-what-s-the-difference-part-2.aspx.

     

    -Brian

  5. Since you are running on Windows, I'd suggest you use the driver that is produced by Microsoft (the sqlsrv driver).

     

    You can download the sqlsrv driver here: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9.

    This video will show you how to install it:

    .

    This topic in the documentation shows you how to call a stored procedure: http://msdn.microsoft.com/en-us/library/cc296167(SQL.90).aspx

     

    If you are interested int the difference between the sqlsrv and mssql drivers, there are some topics here: http://blogs.msdn.com/brian_swan/archive/tags/mssql+driver/default.aspx

     

    Hope that helps.

     

    -Brian

  6. Not sure I understand your last question. If you install the sqlsrv driver just like you would any other PHP extension (put the .dll in the extension directory, add extension=php_sqlsrv.dll to your php.ini file, then restart your web server), the driver should be loaded and ready to use.

     

    Is that what you were asking?

     

    -Brian

  7. You might want to consider using the PHP driver (sqlsrv) released by Microsoft. There is more information about the difference between the mssql and the sqlsrv divers here: http://blogs.msdn.com/brian_swan/archive/2010/03/08/mssql-vs-sqlsrv-what-s-the-difference-part-1.aspx. If you choose to go that route, this might be helpful for getting set up: http://blogs.msdn.com/brian_swan/archive/2010/02/08/getting-started-with-the-sql-server-driver-for-php.aspx.

     

    To your last question, you shouldn't have any problems with the web server and database server being on different machines as long as your database server is configured to allow remote connections.

     

    Hope that helps.

     

    -Brian

  8. Although the recommended way to execute store procedures witht the sqlsrv driver is to use the "call" syntax, you can use the EXEC syntax. So if your stored procerdure declares a default value for a param, like for @test here:

     

    CREATE PROCEDURE GetEmployeeSalesYTD
    @SalesPerson nvarchar(50),
    @test nvarchar(50) = null,
    @SalesYTD money OUTPUT
    AS
    SELECT @SalesYTD = SalesYTD
    FROM Sales.SalesPerson AS sp
    JOIN HumanResources.vEmployee AS e 
    ON e.BusinessEntityID = sp.BusinessEntityID
    WHERE LastName = @SalesPerson

     

    ...then you shoul be able to do this...

     

    $tsql_callSP = "EXEC GetEmployeeSalesYTD @SalesPerson=?, @SalesYTD=?";
    $lastName = "Blythe";
    $salesYTD = 0.0;
    $params = array( 
                     array($lastName, SQLSRV_PARAM_IN),
                     array($salesYTD, SQLSRV_PARAM_OUT)
                   );
    
    /* Execute the query. */
    $stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
    if( $stmt3 === false )
    {
         echo "Error in executing statement 3.\n";
         die( print_r( sqlsrv_errors(), true));
    }
    
    /* Display the value of the output parameter $salesYTD. */
    echo "YTD sales for ".$lastName." are ". $salesYTD. ".";

     

    Does that help?

  9. I’m a part of the team working on the Microsoft SQL Server 2005 Driver for PHP.  I want to let people know about the release today of our first Community Technology Preview. We are excited about this release largely because it gives us the opportunity to receive feedback from the PHP community.  We continue to work hard toward developing this driver, but want to do so with the benefit of your comments and insight.

     

    The bits and documentation can be downloaded here: http://www.microsoft.com/downloads/details.aspx?FamilyId=85F99A70-5DF5-4558-991F-8AEE8506833C&displaylang=en. Visit our team blog to provide feedback: http://blogs.msdn.com/sqlphp. For peer-to-peer support, visit the SQL Server Data Access Forum:  http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=87&SiteID=1.

     

    Thanks.

    Brian Swan

    Programming Writer

    Microsoft

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.