[RESOLVED] Embedded SQL in PHP one version works the other does not...
Results 1 to 3 of 3

Thread: [RESOLVED] Embedded SQL in PHP one version works the other does not...

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    2

    resolved [RESOLVED] Embedded SQL in PHP one version works the other does not...

    PHP Code:
    //$sql = "DESCRIBE ".$table;
    $sql "DESCRIBE '$table' ";
    $result $con->query($sql);
    $resultarray=$result->fetchAll(); 
    I would like to know why using SQL statement in line 2
    PHP Code:
    $sql "DESCRIBE '$table' "
    does not execute properly and results in the error;

    "Fatal error: Call to a member function fetchAll() on a non-object in.."

    shown on the last line of the paste whereas SQL statement in line 1
    PHP Code:
    $sql "DESCRIBE ".$table
    executes just fine.

    I am using Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 in XAMPP
    and MySQL Server version: 5.5.16

    P.S. From what I v been reading I am aware that I probably should be using PDO prepare/execute statements for SQL with parameters...
    Last edited by bradgrafelman; 02-19-2013 at 10:40 AM. Reason: code moved from external site to be inline w/ post

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,414
    Single quotes are used to delimit strings, not identifiers. The latter are delimited either by double quotes (standard SQL and/or MySQL in ANSI_QUOTES mode) or by backticks (MySQL only, IIRC). (See MySQL manual page 9.2.1. Identifier Qualifiers.)

    EDIT: As to why you're getting that exact error message, that would be because the code was poorly written and didn't verify that the query was successfully executed and, if not, logged and/or outputted the SQL error message to aid in debugging.
    Last edited by bradgrafelman; 02-19-2013 at 10:43 AM.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thank u for your explanation and for fixing my initial post

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •