1. Please take 30 seconds to register your free account to remove most ads, post topics, make friends, earn reward points at our store, and more!  

Any MySQL or Microsoft SQL database guys? code in PHP pages.

Discussion in 'Off Topic [BG]' started by rydin4lifebass, Nov 29, 2018.

  1. I just inherited a few .php pages that are part of a larger website. The code within these pages contains MySQL code that is used to display information housed in a MySQL database. The code now needs to be changed to reflect the data in a Microsoft SQL database. The data is the same and the field names are the same, just that it's now housed in a MS SQL database instead of MySQL. I'm not familiar wtih this at all and was wondering if anyone knows of any sites that can take the MySQL code as input and output the applicable MS SQL code? If not that, are there good resources for translation, as is abc in MySQL = xyz in MS SQL?

    Any input is much appreciated.
  2. OldDog52

    OldDog52 Gold Supporting Member

    Jan 1, 2011
    Wanker_Joe likes this.
  3. mrcbass


    Jan 14, 2016
    Sacramento, CA
    This is a common issue when changing data source types. It's been along time since I worked in PHP and never did so with SQL server, but I bet just updating the connect string will go a long way to fixing your issues. Just Google for PHP SQL Server Connect Strings and you'll get lots of options to explore.

    If you're using any functions in the PHP code, those may require some attention as well.

    Good luck!
  4. I dealt with a migration like that years ago. The thing I remember most about it was that what I thought were single quotes (') were actually backticks (`). It did not show up so obvious on the screen or in print. Once I figured that out and replaced the backticks with single quotes, things went much smoother.

    If I remember right, I did what @mrcbass suggested. I had to manually change some things, but I think most of it was compatible.
  5. MJ5150

    MJ5150 Moderator Staff Member Supporting Member

    Apr 12, 2001
    Olympia, WA
    Be sure and verify compatibility and versions between the DB you're moving from and moving to.
    Sometimes queries/commands are deprecated for example.

  6. IconBasser

    IconBasser Scuba Viking Supporting Member

    Feb 28, 2007
    Alta Loma, California
    Sorry, I only know Oracle :atoz:
  7. MJ5150 likes this.
  8. MJ5150

    MJ5150 Moderator Staff Member Supporting Member

    Apr 12, 2001
    Olympia, WA
    I'm no SQL expert, but I know my way around. I remember well being in the position you're in now, and was grateful then for the advice and direction I got from others more experienced than I.

  9. Wanker_Joe


    Sep 26, 2017
    Hey! I've done this numerous times, moving from MS SQL to MySQL and back and to other DBs. Generally, so long as you aren't using anything that specific to one system or the other (i.e.: you code is more or less ANSI SQL) then you should be good to go once you change your connection string to point to the other DB.

    Mostly the conversion between the two is straightforward. However, if there are any parameters (you are using prepared statements in MySQL) you'll probably want to change those to MSSQL stored procs or at the very least if you have to use in-line SQL code you'll want to parameterize them. So if you see something like $MySQL-> prepare('some statement that has a parameter like this (?)'); you will want to examine that one closely, as it will likely be a good candidate for a stored proc, or at the very least you'll need to ensure it's handled like a MSSQL parameterized query by PHP.

    Speaking of which, make sure you are on the lookout for SQL injection issues! Way too much PHP/MySQL code, especially if it's older is rife with SQL-I issues. You don't want to be the developer who gets blamed when your org gets hacked!

  10. hs123


    Aug 11, 2011
    Westminster CO
    This can be as simple as modifying your connection string (odbc driver, usename, password) if there's nothing too fancy going on in your sql.
    MJ5150 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.