Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8647899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:11:13+00:00 2026-06-12T13:11:13+00:00

My problem is this: I Created a store procedure from php to mysql. Now

  • 0

My problem is this:
I Created a store procedure from php to mysql. Now before someone says something about that practice, The procedure works fine.
The problem is this, when I call the procedure from php and I KNOW that a record has been entered, mysql_insert_id(), returns 0… Any ideas why?

Oh, and yes, my id field is AUTO_INCREMENT and PRIMARY KEY

p.s
If there’s an easy way to format my code in here, pls tell me. I put pre in html, but it doesn’t seem to work very well.

Ty in advance.

$PROCEDURE_INSERT_UPDATE_BOARD = 
"
CREATE PROCEDURE InsertUpdateBoard(IN `pNewBoardUUID` CHAR(36),
                                   IN `pOldBoardUUID` CHAR(36),
                                   IN `pSimName` VARCHAR(40), 
                                   IN `pOwnerName` VARCHAR(64),
                                   IN `pOwnerUUID` CHAR(36),
                                   IN `pLandmark` VARCHAR(80),
                                   IN `pVersion` VARCHAR(10),
                                   IN `pManagerUUID` CHAR(36),
                                   IN `pBoardURL`    CHAR(80),
                                   IN `pPassword` CHAR(8))
    BEGIN   
        CALL InsertUpdateSims(`pSimName`); 
        CALL InsertUpdateAvatars(`pOwnerName`, `pOwnerUUID`);

        INSERT INTO boards(`boardUUID`, `simId`, `ownerId`, `landmark`,
                                   `version`, `managerId`, `boardURL`, `password`)
                            VALUES(`pOldBoardUUID`,                                      
                            (SELECT rS.id FROM 2starsglobal.sims AS rS
                                    WHERE rS.name=`pSimName`),
                            (SELECT rA.id FROM 2starsglobal.avatars AS rA
                                    WHERE rA.UUID = `pOwnerUUID`),
                            `pLandmark`, `pVersion`,
                            (SELECT rA2.id FROM 2starsglobal.avatars AS rA2 
                                    WHERE rA2.UUID = `pManagerUUID`),
                            `pBoardURL`, 
                            `pPassword`)
        ON DUPLICATE KEY UPDATE `boardUUID`=`pNewBoardUUID`, 
                    `landmark`=`pLandmark`, `version`=`pVersion`,
                    `boardURL`=`pBoardURL`; 
    END
";

And the Php code

function InsertUpdateBoard($boardNewUUID, $boardOldUUID, $simName, 
                           $ownerName, $ownerUUID, $boardLandmark,
                           $versionNumber, $managerUUID, $boardURL)
{ 
    $password = generatePassword(8);

    $query = "CALL InsertUpdateBoard('$boardNewUUID', '$boardOldUUID', '$simName', 
                                         '$ownerName', '$ownerUUID', '$boardLandmark', 
                                         '$versionNumber', '$managerUUID', '$boardURL',
                                         '$password')";

    mysql_query($query) or die("ERROR:QUERY_FAILED " . mysql_error());  

    if(mysql_affected_rows() > 0)
    {
        if(mysql_insert_id() > 0)
        {    
            echo "SUCCESS,$password";
        }
        else 
        {
            echo "SUCCESS"; 
        }
    }
    else
    {
        echo 'FAILED:BOARD_REGISTRATION_UPDATE'; 
    }       

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:11:14+00:00Added an answer on June 12, 2026 at 1:11 pm

    Ten seconds with google found this page

    Note that if you Call a MySQL stored procedure to insert a new record
    and then reference $db->insert_id; you will get 0 back, not the last
    inserted ID.

    It is therefore necessary to add a line to your MySQL Stored Procedure
    such as

    select last_insert_id() as intRecordKey;

    after the insert so that the query will return the new key value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem getting my newly created php project on Netbeans work on
I bumped into this problem when I created a chart that need a axis
I have this stored procedure for Oracle: create or replace procedure bns_saa_message_get() <--- PROBLEM
Im create this code to store page view in database, but i have problem
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
I have created this Fiddle with this code: This is my problem I want
I'm having this really mind breaking problem. I created a Localizable.strings file in XCode
I'm trying to create this effect: http://www.thecssninja.com/demo/css_tree/ the problem I'm having is that the
What is the trick in MySql (Version 4) to write from PHP thtree Inserts
I'm having a never-ending problem with trying to call a stored procedure from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.