There is a simple database.
root@localhost [project_db]> describe articles_table; +------------------------+--------------+------+-----+---------+------ +-+ | Field | Type | Null | Key | Default | Extra + | +------------------------+--------------+------+-----+---------+------ +-+ | db_art_id | bigint | YES | MUL | NULL | + |

I need the highest article ID in the column "db_art_id".
This works just fine from the console:
root@localhost [project_db]> SELECT MAX(db_art_id) FROM articles_table +; [...] +----------------+ | MAX(db_art_id) | +----------------+ | 1 | +----------------+ 1 row in set (0.01 sec) root@localhost [project_db]>
However, when using DBI, the command errors out with this error info:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM articles_table' at line 1
If I put the articles table into double quotation marks, the error message is slightly different:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"articles_table"' at line 1

As said, the errors occur ONLY from DBI!
To make sure that there is no permissions problem etc, I even let DBI log on the MySQL server as root.

Any idea how to proceed when when things just look and work fine on the server console, but throw syntax errors when using DBI?
Edit:

Basically the code that fails is this:
my $my_articletable = 'articles_table'; my $p_db_art_id = 'db_art_id'; my $sqlcmd = "SELECT MAX($p_db_art_id) FROM $my_articletable;"; logit("SQLCMD: '$sqlcmd'"); my $sth = $p_dbh->prepare($sqlcmd); $sth->execute();

As said, copypasting the resulting SQL command "SELECT MAX(db_art_id) FROM articles_table;" from the logfile into the MySQL monitor console does not give any hint what could be wrong, it just does what it is supposed to do.

In reply to [SOLVED] Need advice how to diagnose the problem when syntax using MAX() is correct according to MySQL monitor, but errors out in DBI by dissident

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.