Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 06-10-2007, 12:23 AM   #1
McHenry
 
McHenry's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 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`(_testname 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("call 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_rows;
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 ?


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 06-10-2007, 12:23 AM   #2
robert
 
robert's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Is this a bug ?

it may have been good to keep this in your last post thread. i had asked in
that thread to see exactly what you've posted here. either way, it's good
for us to see. have you tried isolating the problem using simple examples
that have been known to work? this is a quick one that i've run and it
outputs as expected.

===========

<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

mysqli_query($link, "CREATE TABLE myCity LIKE City");

$query = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart',
617000)";
mysqli_query($link, $query);

printf ("New Record has id %d.\n", mysqli_insert_id($link));

/* drop table */
mysqli_query($link, "DROP TABLE myCity");

/* close connection */
mysqli_close($link);
?>


===========

the "myCity" table has to be made from scratch...but you could substitute it
w/ your own. what we're trying to do here is just get *something* to work.
once that happens, we can introduce new factors until it no longer works...i
suspect it may be with the binding.

i'm not sure if they name bugs after people...but you're welcome to it. ;^)
and, there have been several bugs in the past related to the insert_id. once
reported, they are fixed promptly. we just have to document where it breaks.


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-10-2007, 12:23 AM   #3
McHenry
 
McHenry's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Is this a bug ?


"robert" <ab@no.spam-alama-ding-dong> wrote in message
news9U5g.63$tD3.60@fe03.lga...
> it may have been good to keep this in your last post thread. i had asked
> in
> that thread to see exactly what you've posted here. either way, it's good
> for us to see. have you tried isolating the problem using simple examples
> that have been known to work? this is a quick one that i've run and it
> outputs as expected.


I posted the new thread after I had received your reply asking for the
details sorry.
The example I posted was a trivial example which illustrates the scenario
however the real stored procedure is more complex.
I would prefer to keep the sql within a sp if possible.

p.s. Nice choice of city !!!


>
> ===========
>
> <?php
> $link = mysqli_connect("localhost", "my_user", "my_password", "world");
>
> /* check connection */
> if (mysqli_connect_errno()) {
> printf("Connect failed: %s\n", mysqli_connect_error());
> exit();
> }
>
> mysqli_query($link, "CREATE TABLE myCity LIKE City");
>
> $query = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU',
> 'Stuttgart',
> 617000)";
> mysqli_query($link, $query);
>
> printf ("New Record has id %d.\n", mysqli_insert_id($link));
>
> /* drop table */
> mysqli_query($link, "DROP TABLE myCity");
>
> /* close connection */
> mysqli_close($link);
> ?>
>
>
> ===========
>
> the "myCity" table has to be made from scratch...but you could substitute
> it
> w/ your own. what we're trying to do here is just get *something* to work.
> once that happens, we can introduce new factors until it no longer
> works...i
> suspect it may be with the binding.
>
> i'm not sure if they name bugs after people...but you're welcome to it.
> ;^)
> and, there have been several bugs in the past related to the insert_id.
> once
> reported, they are fixed promptly. we just have to document where it
> breaks.
>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-10-2007, 12:23 AM   #4
robert
 
robert's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Is this a bug ?

| I posted the new thread after I had received your reply asking for the
| details sorry.

no big. no need for sorries.

| The example I posted was a trivial example which illustrates the scenario
| however the real stored procedure is more complex.
| I would prefer to keep the sql within a sp if possible.

it should be fine to keep all your sql in the sp. i take it that this
simplified example you posted doesn't return the insert_id either...right?
the more complex one is ultimately performing an insert...right? updates
return a insert_id too. well...lol...supposed to. we have to get there
first.

| p.s. Nice choice of city !!!

you know i'm braindead! i just grabbed this example off the net and gave it
a shot on my pc with as little modification as possible. granted, i do know
where stuttgart is...but i can guarantee you, i couldn't spell it to save my
life. ;^) i suppose brisbane would have garnered a more picturesque
ambiance. ;^)

|
| >
| > ===========
| >
| > <?php
| > $link = mysqli_connect("localhost", "my_user", "my_password", "world");
| >
| > /* check connection */
| > if (mysqli_connect_errno()) {
| > printf("Connect failed: %s\n", mysqli_connect_error());
| > exit();
| > }
| >
| > mysqli_query($link, "CREATE TABLE myCity LIKE City");
| >
| > $query = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU',
| > 'Stuttgart',
| > 617000)";
| > mysqli_query($link, $query);
| >
| > printf ("New Record has id %d.\n", mysqli_insert_id($link));
| >
| > /* drop table */
| > mysqli_query($link, "DROP TABLE myCity");
| >
| > /* close connection */
| > mysqli_close($link);
| > ?>
| >
| >
| > ===========
| >
| > the "myCity" table has to be made from scratch...but you could
substitute
| > it
| > w/ your own. what we're trying to do here is just get *something* to
work.
| > once that happens, we can introduce new factors until it no longer
| > works...i
| > suspect it may be with the binding.
| >
| > i'm not sure if they name bugs after people...but you're welcome to it.
| > ;^)
| > and, there have been several bugs in the past related to the insert_id.
| > once
| > reported, they are fixed promptly. we just have to document where it
| > breaks.
| >
| >
|
|


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-10-2007, 12:23 AM   #5
McHenry
 
McHenry's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Is this a bug ?


"robert" <ab@no.spam-alama-ding-dong> wrote in message
news:_vU5g.71$tD3.27@fe03.lga...
>| I posted the new thread after I had received your reply asking for the
> | details sorry.
>
> no big. no need for sorries.
>
> | The example I posted was a trivial example which illustrates the
> scenario
> | however the real stored procedure is more complex.
> | I would prefer to keep the sql within a sp if possible.
>
> it should be fine to keep all your sql in the sp. i take it that this
> simplified example you posted doesn't return the insert_id either...right?
> the more complex one is ultimately performing an insert...right? updates
> return a insert_id too. well...lol...supposed to. we have to get there
> first.


Correct, the simplified example is exactly the same scenario and exhibits
the same problems as the real example, if we can solve the simple one the
solution will carry over I'm sure.

>
> | p.s. Nice choice of city !!!
>
> you know i'm braindead! i just grabbed this example off the net and gave
> it
> a shot on my pc with as little modification as possible. granted, i do
> know
> where stuttgart is...but i can guarantee you, i couldn't spell it to save
> my
> life. ;^) i suppose brisbane would have garnered a more picturesque
> ambiance. ;^)


Home of Porsche...

>
> |
> | >
> | > ===========
> | >
> | > <?php
> | > $link = mysqli_connect("localhost", "my_user", "my_password",
> "world");
> | >
> | > /* check connection */
> | > if (mysqli_connect_errno()) {
> | > printf("Connect failed: %s\n", mysqli_connect_error());
> | > exit();
> | > }
> | >
> | > mysqli_query($link, "CREATE TABLE myCity LIKE City");
> | >
> | > $query = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU',
> | > 'Stuttgart',
> | > 617000)";
> | > mysqli_query($link, $query);
> | >
> | > printf ("New Record has id %d.\n", mysqli_insert_id($link));
> | >
> | > /* drop table */
> | > mysqli_query($link, "DROP TABLE myCity");
> | >
> | > /* close connection */
> | > mysqli_close($link);
> | > ?>
> | >
> | >
> | > ===========
> | >
> | > the "myCity" table has to be made from scratch...but you could
> substitute
> | > it
> | > w/ your own. what we're trying to do here is just get *something* to
> work.
> | > once that happens, we can introduce new factors until it no longer
> | > works...i
> | > suspect it may be with the binding.
> | >
> | > i'm not sure if they name bugs after people...but you're welcome to
> it.
> | > ;^)
> | > and, there have been several bugs in the past related to the
> insert_id.
> | > once
> | > reported, they are fixed promptly. we just have to document where it
> | > breaks.
> | >
> | >
> |
> |
>
>



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-10-2007, 12:23 AM   #6
robert
 
robert's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Is this a bug ?

| Correct, the simplified example is exactly the same scenario and exhibits
| the same problems as the real example, if we can solve the simple one the
| solution will carry over I'm sure.

i'll try and set it up on my pc and see what i get.

| > | p.s. Nice choice of city !!!
| >
| > you know i'm braindead! i just grabbed this example off the net and gave
| > it
| > a shot on my pc with as little modification as possible. granted, i do
| > know
| > where stuttgart is...but i can guarantee you, i couldn't spell it to
save
| > my
| > life. ;^) i suppose brisbane would have garnered a more picturesque
| > ambiance. ;^)
|
| Home of Porsche...

lol. i'm more of a ferrari man myself. ;^)


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags:




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Featured Websites




All times are GMT +1. The time now is 12:45 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

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