Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6206743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:30:09+00:00 2026-05-24T05:30:09+00:00

Background info I’m a guy who isn’t very familiar with MySQL or PHP, who’s

  • 0

Background info

I’m a guy who isn’t very familiar with MySQL or PHP, who’s debugging a project that another guy wrote in MySQL and PHP 🙂

The website is being moved to new servers. Both are Windows servers and serve PHP through IIS.

The old server ran PHP 5.1.2 and MySQL 14.12 Distrib 5.0.22, for Win32.

The new server runs PHP 5.3.6 and MySQL 14.14 Distrib 5.1.57, for Win64

I’ve done my best to match the .ini-files as far as seemed prudent.

Why did the quotes work?

On the old server SQL queries like this seem to work:

$db_query = mysql_query("SELECT * FROM $db_table ORDER BY 'id'")
$db_query = mysql_query("SELECT * FROM $db_table ORDER BY '$orderby'")

On the new server, these queries fail unless I remove the single quotes.

Why did this work on the old server and not on the new one? Is it due to changes between versions in MySQL or PHP?

Why would the guy who programmed it use single quotes in the first place?

Oh, and before you guys start raving about injection attacks – we’re aware of the risks – this site is strictly for internal use

EDIT

I found this piece of code:

$db_query_str = $db_query_str . " ORDER BY '$orderby' DESC";
[...code...]
$db_query = $mysql_query($db_query_str);

$orderby can be for example dateofpurchase.

As far as I understand, this would result in a query string that ends with ORDER BY 'dateofpurchase' DESC? That still looks strange to my eyes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:30:10+00:00Added an answer on May 24, 2026 at 5:30 am

    This has never been correct.

    ORDER BY 'id'
    

    …means, literally, “order by the word id”, not the value of a column named id. Single quotes can only ever surround an identifier when an alias is being declared.

    This would not produce the correct ordering in MySQL 5.0.22 or 5.1.57 (or any 5.x or any 4.x) except by chance (a table that happens to be ordered by id on disk because it hasn’t had deletions/reinsertions/rebuilt).

    ORDER BY `id`
    

    …would be fine, and necessary if $orderby can ever contain a reserved word that you used as a column name or alias.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background info: I've set up a very simple .NET solution in VS2008 that contains
Background info: I'm using Microsoft Visual C# 2010 for this project. I want to
Background info: I have a windows application (in c#) that handles a custom file
Background info: I've recently decided to take on a project of making a social
First I will give a little background info so this question isn't completely without
Background Info: I have a large body of text that I regularly encapsulate in
Quick background info: of the three database tables that are relevant for this question,
Relevant background info I've built a little software that can be customized via a
Here's some background info. I have three MySQL tables (all InnoDB). The first table
Some background info I am programming in a system that uses a proprietary programming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.