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

  • Home
  • SEARCH
  • 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 6370849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:58:59+00:00 2026-05-25T00:58:59+00:00

My procedures mysql already does inserts correctly: this is my php code calling the

  • 0

My procedures mysql already does inserts correctly:

this is my php code calling the procedure:

$sql = 'CALL insert_menu(?,?,?,?,?)';
        try {
                  $query = $bd->prepare($sql);
                  $query->bindParam(1,$name, PDO::PARAM_STR);
                  $query->bindParam(2,$catsup, PDO::PARAM_INT);
                  $query->bindParam(3,$level, PDO::PARAM_INT);
                  $query->bindParam(4,$link, PDO::PARAM_STR);
                  $query->bindParam(5,$title, PDO::PARAM_STR);
                  $query->execute();
        } catch (PDOException $e) {
                echo $e->getMessage();
        }

and this is my procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_menu`(
IN p_cat_name VARCHAR(100),
IN p_cat_sup_cod INT,
IN p_cat_level INT,
IN p_link VARCHAR(200),
IN p_title VARCHAR(100)
)
BEGIN
IF ((p_cat_name <> '')&&(p_cat_level <> '')&&(p_link <> '')&&(p_title <> '')) THEN
INSERT INTO access (access_id,menu_descr,sup_cod,level,menu_link,menu_title)
VALUES ('',p_cat_name,p_cat_sup_cod,p_cat_level,p_link,p_title);
END IF;
END;

I would like that my procedure returns to the php the last inserted id…
I also do not know how to get the result with PDO prepare…
I ask everyone’s help, thank you …

  • 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-05-25T00:59:00+00:00Added an answer on May 25, 2026 at 12:59 am

    Since you’re using PDO:

    try {
        $bd->prepare('SELECT LAST_INSERT_ID()');
        $bd->execute();
    } catch(PDOException $e) {
        echo $e->getMessage();
    }
    

    But this really doesn’t need a prepare, so you could just use:

    try {
        $results = $bd->query('SELECT LAST_INSERT_ID() as last');
        $lastID = $results[0]['last'];
    } catch(PDOException $e) {
        echo $e->getMessage();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've rewritten my site php-code and added MySQL Stored Procedures. In my local version
Converting a couple stored procedures from MySQL to Microsoft SQL server. Everything is going
I've got a mySql stored procedure that looks like this-- delimiter | create procedure
Well I have this MySQL stored procedure that I wrote and if I run
How do you build and use dynamic sql in a MySQL stored procedure?
Is there a Java equivalent to PHP's mysql_real_escape_string() ? This is to escape SQL
I'm banging my head on this SQL puzzle since a couple of hours already,
I m calling a stored procedure inside another stored procedure in MySQL The error
I'm writing some procedures in MySql rather than MS SQL, and I'm having a
Can I use named parameters for stored procedures in MySQL? I need to call

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.