Data Driver

Blog archive

PHP Meets SQL Server -- Converting MySQL Queries

As an addendum to last week's post about a recent SQL Server camp held for PHP developers, Microsoft's Brian Swan has published some new nuts-and-bolts details for converting MySQL queries.

Swan, who blogs on the "At the Intersection of PHP and Microsoft" page, said he learned the technique at the JumpIn! camp, where Microsoft hosted some 17 prominent PHP developers in order to share ideas and educate them about the process of supporting SQL Server and SQL Azure in their PHP applications.

He said it was "an excellent two-way learning experience" and one of the things he learned was that the SQL Server Migration Assistant for MySQL 1.0 (SSMA) can convert specific database queries in addition to its main job of converting databases.

Swan explains the relatively straightforward process by using SSMA to convert the MySQL query:

SELECT post_title, post_date FROM wp_posts ORDER BY post_date LIMIT 5 OFFSET 5;

to the SQL Server query:

SELECT TOP (5) ssma$sub1.post_title, ssma$sub1.post_date
FROM
  (
    SELECT wp_posts.post_title, wp_posts.post_date, ROW_NUMBER() OVER (
      ORDER BY wp_posts.post_date) AS ssma$rownum
    FROM dbo.wp_posts
   ) AS ssma$sub1
WHERE ssma$sub1.[ssma$rownum] > 5
ORDER BY ssma$sub1.[ssma$rownum]
GO

(Whew! If I'm a noob evaluating the two on the basis of query simplicity, it's pretty clear which direction I'd lean.)

Swan noted that all queries won't translate successfully (if they contain functions specific to MySQL, for example), but even if it doesn't work, it can provide clues to help write the translated query yourself.

Do you have experience in supporting SQL Server in PHP apps? Is MySQL really that much simpler than SQL Server? Please share your thoughts here or drop me a line.

Posted by David Ramel on 12/08/2010


comments powered by Disqus

Featured

  • Copilot Agent Mode Preview Highlights New Visual Studio 17.14 Release

    Agent mode, now in public preview for Visual Studio 17.14, marks a major step forward for AI-assisted development. Unlike previous Copilot features, agent mode can autonomously plan, edit, iterate, and invoke trusted tools-completing complex coding tasks from a single natural language prompt.

  • Microsoft Busts the 'Myth of AI/ML and Java'

    Microsoft, contradicting beliefs of Java developers responding to a survey, said they don't need to learn AI, master machine learning, or switch to Python to build intelligent, production-ready applications.

  • Predicting the Future Using Azure Machine Learning

    Eric D. Boyd of responsiveX previews his VSLive! 2025 session at Microsoft HQ in August where he explains how Azure ML empowers teams to build, deploy, and manage machine learning models with ease and confidence.

  • VS Code 1.10 Showcases New, Detailed Markdown Copilot Prompting

    The new way to get the most out of GitHub Copilot is from markdown prompting, or writing detailed, reusable natural-language instructions in files like README.md or copilot-instructions.md to guide different AI models in generating context-aware, accurate code.

  • Uno Platform Studio and 'Hot Design' Reach General Availability

    Uno Platform, a .NET-centric open source project for building single-codebase apps across multiple platforms, this week announced v6.0 of its flagship offering, which introduces a zero-install, web-based IDE for rapid cross-platform development, alongside a modernized app architecture that embraces MVU and .NET-style extensions.

Subscribe on YouTube