Parameters to SQL statements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Poley

    Parameters to SQL statements

    I'm new to PHP. I have successfully set up a small script which pulls
    data out of an Access database and puts it in an HTML page, using an SQL
    query:
    "SELECT * FROM ZWobservations WHERE Country = 'CY'"

    I now want to parameterise this, like:
    "SELECT * FROM ZWobservations WHERE Country = ?"

    but have not managed to work out how to get this running. I'm getting
    errors like:
    "Warning: SQL error: [Microsoft][ODBC Microsoft
    Access-stuurprogramma]Het veld COUNT is onjuist , SQL state 07001 in
    SQLExecute"

    The PHP manual is short on examples (to put it mildly) and Googling for
    a tutorial or working example has had a surprising lack of success -
    apparently I'm choosing just the wrong search terms.

    Could someone point me to a working example / tutorial?

    --
    Stephen Poley
    Barendrecht, Holland
  • sotto

    #2
    Re: Parameters to SQL statements

    Try something like:

    $parm = "CY";
    $sql = "SELECT * FROM ZWobservations WHERE Country = '$parm'";

    also take a look at the sql statement "select * from x where y like
    '%test%'"

    hope this helps

    On Fri, 18 Jul 2003 13:36:29 +0200, Stephen Poley wrote:
    [color=blue]
    > I'm new to PHP. I have successfully set up a small script which pulls data
    > out of an Access database and puts it in an HTML page, using an SQL query:
    > "SELECT * FROM ZWobservations WHERE Country = 'CY'"
    >
    > I now want to parameterise this, like: "SELECT * FROM ZWobservations WHERE
    > Country = ?"
    >
    > but have not managed to work out how to get this running. I'm getting
    > errors like:
    > "Warning: SQL error: [Microsoft][ODBC Microsoft Access-stuurprogramma]Het
    > veld COUNT is onjuist , SQL state 07001 in SQLExecute"
    >
    > The PHP manual is short on examples (to put it mildly) and Googling for a
    > tutorial or working example has had a surprising lack of success -
    > apparently I'm choosing just the wrong search terms.
    >
    > Could someone point me to a working example / tutorial?[/color]

    Comment

    • Stephen Poley

      #3
      Re: Parameters to SQL statements

      On Fri, 18 Jul 2003 13:44:01 +0200, "sotto" <junk@sotto.b e> wrote:
      [color=blue]
      >Try something like:
      >
      >$parm = "CY";
      >$sql = "SELECT * FROM ZWobservations WHERE Country = '$parm'";
      >
      >also take a look at the sql statement "select * from x where y like
      >'%test%'"
      >
      >hope this helps[/color]

      Well, yes I can do it that way of course. But it seems to render the
      odbc_prepare and odbc_execute calls rather redundant - to say nothing of
      the parameters_arra y parameter to odbc_execute. One ends up using
      odbc_exec the whole time. I've done it using SQL parameters in Perl, and
      the PHP manual certainly makes it look as if the intention is to do it
      similarly, but I'm missing out on the fine detail somewhere.

      --
      Stephen Poley
      Barendrecht, Holland

      Comment

      Working...