Is this a bug ?

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

    #1

    Is this a bug ?

    I am trying to add a new row to a MySQL table using a stored procedure and
    then obtain the new id value. The rows are added and affected _rows returns
    1 confirming the statement worked however no insert_id value is returned.
    The results of running this script are:

    New ID:0 New Rows:1

    MySQL Code
    =============== =============== =============== =

    CREATE TABLE testing (
    testid INT AUTO_INCREMENT PRIMARY KEY,
    testname VARCHAR(25)
    )


    CREATE PROCEDURE `addtest`(_test name VARCHAR(25))
    INSERT INTO testing (testname) VALUES (_testname)


    PHP Code
    =============== =============== =============== =
    <?php
    $testname = "McHenry";

    //Open the connection
    $mysqli = new mysqli("******* ***", "********** ", "********** ",
    "********** ");

    // create the statement
    $stmt = $mysqli->prepare("cal l addtest(?)");

    /* bind parameters for markers */
    $stmt->bind_param("s" , $testname);

    /* execute query */
    $stmt->execute();

    //Return the status of the query and display
    $newid=$mysqli->insert_id;
    $affected_rows= $stmt->affected_row s;
    Echo "New ID:$newid New Rows:$affected_ rows";

    /* close statement */
    $stmt->close();

    /* close connection */
    $mysqli->close();
    ?>

    Thanks in advance...

    p.s. If this is a bug is it treated like a new comet etc, do they name it
    after you ?



  • Tim Roberts

    #2
    Re: Is this a bug ?

    "McHenry" <mchenry@mchenr y.com> wrote:
    [color=blue]
    >I am trying to add a new row to a MySQL table using a stored procedure and
    >then obtain the new id value. The rows are added and affected _rows returns
    >1 confirming the statement worked however no insert_id value is returned.[/color]

    What happens if you try $mysqli->query("SELEC T LAST_INSERT_ID( );")? That
    should be equivalent.
    --
    - Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    • McHenry

      #3
      Re: Is this a bug ?


      "Tim Roberts" <timr@probo.com > wrote in message
      news:bdjg52pcs8 1bsd1sfmqru09t8 jribr24bi@4ax.c om...[color=blue]
      > "McHenry" <mchenry@mchenr y.com> wrote:
      >[color=green]
      >>I am trying to add a new row to a MySQL table using a stored procedure and
      >>then obtain the new id value. The rows are added and affected _rows
      >>returns
      >>1 confirming the statement worked however no insert_id value is returned.[/color]
      >
      > What happens if you try $mysqli->query("SELEC T LAST_INSERT_ID( );")? That
      > should be equivalent.
      > --
      > - Tim Roberts, timr@probo.com
      > Providenza & Boekelheide, Inc.[/color]

      Works, thanks a million...

      Does this mean I get a bug named after me ?
      I've decided to call it Zorgon !


      Comment

      Working...