Likes Likes:  0
Resultaten 1 tot 3 van de 3
Geen
  1. #1
    Tim Stoop
    [PHP] PEAR DB en prepared statements
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    [PHP] PEAR DB en prepared statements

    Hoi mensen,

    Kan iemand me een stukje voorbeeld-code aangeven van hoe ik in PEAR omga met
    prepared statements? Hoe maak ik ze aan en hoe gebruik ik ze? Ik vind wel
    het commando prepare($query), maar nergens een voorbeeld van hoe ik de
    variabelen in de query instel...

    Alvast bedankt!

    --
    Gegroet/Greetings,
    Tim

  2. #2
    Daniel Tryba
    [PHP] PEAR DB en prepared statements
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: [PHP] PEAR DB en prepared statements

    Tim Stoop <cvdSP@mmens-informatica.net> wrote:
    > Kan iemand me een stukje voorbeeld-code aangeven van hoe ik in PEAR omga met
    > prepared statements? Hoe maak ik ze aan en hoe gebruik ik ze? Ik vind wel
    > het commando prepare($query), maar nergens een voorbeeld van hoe ik de
    > variabelen in de query instel...


    Hmmm, het staat toch echt gewoon in de documentatie van PEAR:B
    Na een prepare moet je een execute doen, en _daar_ geef je je parameters
    aan mee in de vorm van een array:

    http://pear.php.net/manual/en/core.db.prepare.php
    <quote>
    See "Execute"-section for further information.
    </quote>

    http://pear.php.net/manual/en/core.db.tut_execute.php
    <quote>
    Execute/ ExecuteMultiple

    After preparing the statement, you can excute the query. This means to
    assign the variables to the prepared statement. To do this, execute()
    requires two arguments, the statement handle of prepare() and an array
    with the values to assign. The array has to be numerically ordered. The
    first entry of the array represents the first wildcard, the second the
    second wildcard etc. The order is independent from the used wildcard
    char.
    <?php
    // Example inserting data
    $alldata = array(array(1, 'one', 'en'),
    array(2, 'two', 'to'),
    array(3, 'three', 'tre'),
    array(4, 'four', 'fire'));
    $sth = $dbh->prepare("INSERT INTO numbers VALUES(?,?,?)");
    foreach ($alldata as $row) {
    $dbh->execute($sth, $row);
    }
    ?>

    In the example the query is done four times:
    INSERT INTO numbers VALUES( '1', 'one', 'en')
    INSERT INTO numbers VALUES( '2', 'two', 'to')
    INSERT INTO numbers VALUES( '3', 'three', 'tre')
    INSERT INTO numbers VALUES( '4', 'four', 'fire')
    </quote>

    --

    Daniel Tryba


  3. #3
    Tim Stoop
    [PHP] PEAR DB en prepared statements
    Gast
    n/a Berichten
    Berichten zijn liked



    Thread Starter

    Re: [PHP] PEAR DB en prepared statements

    Daniel Tryba wrote:
    > Hmmm, het staat toch echt gewoon in de documentatie van PEAR:B

    <knip>

    Inderdaad, ik zoek gewoon niet goed genoeg. Bedankt!

    --
    Gegroet/Greetings,
    Tim

Webhostingtalk.nl

Contact

  • Rokin 113-115
  • 1012 KP, Amsterdam
  • Nederland
  • Contact
© Copyright 2001-2026 Webhostingtalk.nl.
Web Statistics