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 6550387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:12:35+00:00 2026-05-25T12:12:35+00:00

I’ve got a CakePHP application connecting to a remote MSSQL server through ODBC, but

  • 0

I’ve got a CakePHP application connecting to a remote MSSQL server through ODBC, but it’s not working as planned. Every query dies becasue it is trying to put backticks around identifiers, which is not correct for MSSQL.

As an example, I have a model called Item for a table called items, and when I call

$this->Item->find('all')

it tries to use the query

SELECT `Item`.`id`, `Item`.`name`, `Item`.`descrtiption` FROM `items` AS `Item` WHERE 1

…and I get an error about invalid syntax near ` at line 1.
Is there anyway to prevent this behaviour and remove the backticks? Or else use square brackets like SQL Server seems to like?

  • 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-25T12:12:35+00:00Added an answer on May 25, 2026 at 12:12 pm

    I recently took a good look around the odbc driver with the intention of using it against MSSQL 2008 in CakePHP 1.3. Unless you are prepared to put a considerable amount of work in then it’s not feasible at present.

    Your immediate problem is that you need to override the default quotes with [ and ]. These are set at the top of the dbo_odbc.php file here

    var $startQuote = "[";
    var $endQuote = "]";
    

    Once you do this the next issue you will run into is the default use of LIMIT, so you’ll need to provide your own limiting function copied from dbo_mssq to override

    /**
     * Returns a limit statement in the correct format for the particular database.
     *
     * @param integer $limit Limit of results returned
     * @param integer $offset Offset from which to start results
     * @return string SQL limit/offset statement
     */
        function limit($limit, $offset = null) {
            if ($limit) {
                $rt = '';
                if (!strpos(strtolower($limit), 'top') || strpos(strtolower($limit), 'top') === 0) {
                    $rt = ' TOP';
                }
                $rt .= ' ' . $limit;
                if (is_int($offset) && $offset > 0) {
                    $rt .= ' OFFSET ' . $offset;
                }
                return $rt;
            }
            return null;
        }
    

    You’ll then run into two problems, neither of which I solved.

    1. In the describe function the odbc_field_type call is not returning a
      field type. I’m not sure how critical this is if you describe the fields in the model, but it doesn’t sound promising.
    2. More crucially, in the fields function that’s used to generate a field list cake works by recursively exploding the . syntax to generate a series of AS aliases. This is fine if you’re recursion level is zero, but with deeper recursion you end up with a field list that looks something like ‘this.that.other AS this_dot_that.other AS this_dot_that_dot_other’, which is invalid MSSQL syntax.

    Neither of these are unsolvable, but at this point I decided it was simpler to reload my server and use the MSSQL driver than continue to chase prblems with the ODBC driver, but YMMV

    ADDED: This question seems to be getting a bit of attention: so anyone who takes this further could they append their code to this answer – and hopefully we can assemble a solution between us.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
i got an object with contents of html markup in it, for example: string
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

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.