Professional Web Applications Themes

SELECT last_insert_id() not working - MySQL

Say I have a database with two columns - column a and column b. Column a has auto_increment enabled. So say I do... INSERT INTO table_name (b) VALUES ('string'); ....and that that results in (4,'string) being inserted. Shouldn't "SELECT last_insert_id()" return "4"? Because when I try it, it always returns 0. Any ideas as to what I'm doing wrong?...

  1. #1

    Default SELECT last_insert_id() not working

    Say I have a database with two columns - column a and column b. Column
    a has auto_increment enabled.

    So say I do...

    INSERT INTO table_name (b) VALUES ('string');

    ....and that that results in (4,'string) being inserted. Shouldn't
    "SELECT last_insert_id()" return "4"? Because when I try it, it always
    returns 0.

    Any ideas as to what I'm doing wrong?

    yawnmoth Guest

  2. #2

    Default Re: SELECT last_insert_id() not working

    >Say I have a database with two columns - column a and column b. Column 

    Yes, if that query is done over the same connection as the insert above.
     

    If you are using a web-based query program, it probably uses a separate
    connection on every query.


    Gordon Guest

  3. #3

    Default Re: SELECT last_insert_id() not working


    Gordon Burditt wrote: 
    >
    > Yes, if that query is done over the same connection as the insert above.

    >
    > If you are using a web-based query program, it probably uses a separate
    > connection on every query.[/ref]
    I'm using "MySQL Query Browser"
    <http://www.mysql.com/products/tools/query-browser/>... would that use
    a seperate connection for each query?

    yawnmoth Guest

  4. #4

    Default Re: SELECT last_insert_id() not working

    On 7 Oct 2006 19:35:11 -0700, "yawnmoth" <com> wrote:
     
    >>
    >> Yes, if that query is done over the same connection as the insert above.
    >> 
    >>
    >> If you are using a web-based query program, it probably uses a separate
    >> connection on every query.[/ref]
    >I'm using "MySQL Query Browser"
    ><http://www.mysql.com/products/tools/query-browser/>... would that use
    >a seperate connection for each query?[/ref]

    MySQL Query Browser DOES use a seperate connection for every query.

    Lee
    Lee Guest

Similar Threads

  1. last_insert_id()
    By lingo_user in forum Macromedia ColdFusion
    Replies: 0
    Last Post: June 29th, 07:26 PM
  2. Replies: 0
    Last Post: September 24th, 03:24 AM
  3. Replies: 0
    Last Post: September 11th, 11:26 AM
  4. Replies: 0
    Last Post: September 11th, 12:19 AM
  5. select not working?
    By Daniel T. in forum Mac Programming
    Replies: 9
    Last Post: July 19th, 12:34 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139