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 8442575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:52:43+00:00 2026-06-10T08:52:43+00:00

I have a MySQL function that looks like this: delimiter # create function activate_user

  • 0

I have a MySQL function that looks like this:

delimiter #
create function activate_user
(
    p_activation_hash char(32)
)
returns int
deterministic
begin
    declare v_ret int unsigned default 0;

    if (char_length(p_activation_hash) != 32) then
        return 0;
    end if;

    insert ignore into users (email, password_hash, first_name, last_name, company_name)
        select email, password_hash, first_name, last_name, company_name
        from user_activation
        where activation_hash = p_activation_hash
        and expiry_date > now();

    return last_insert_id();
end #
delimiter ;

And if I call it like this using CodeIgniter:

$query = $this->db->query("select activate_user(?);", array($this->input->get('key')));

var_dump($query->result_object());

var_dump($query->result_array());

I can get either an array or object of results that looks like this:

array
  0 => 
    object(stdClass)[16]
      public 'activate_user('5c9835e8dee7e1b43691708f503cb7f5')' => string '0' (length=1)

array
  0 => 
    array
      'activate_user('5c9835e8dee7e1b43691708f503cb7f5')' => string '0' (length=1)

Obviously due to the key it isn’t very useable and I don’t really want to do a foreach it seems like there should be a better way?

I thought one of the point big advantages of mysql functions was to return things like integers, but reading these intergers seems messy in php, am I missing something?


For your information this is the most concise I got it:

$query = $this->db->query("select activate_user(?) as user_result;", array($this->input->get('key')));
$result = current($query->result_array());

echo "function result: " . $result['user_result'];
  • 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-10T08:52:44+00:00Added an answer on June 10, 2026 at 8:52 am

    The result is showing you that the function returned zero. If you alias your function call you might have a more sensible time reading the result:

    $query = $this->db->query("select activate_user(?) AS user_result;", array($this->input->get('key')));
    

    Now the function call is aliased to a column name of user_result which is easier to read without needing the key. Then you can read the result as:

    $result = $query->result_array();
    echo "function result = " . $result['user_result'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a connection class for MySQL that looks like this: class MySQLConnect {
I have a table that looks something like this: CREATE TABLE student_results(id integer, name
Using MySQL, i have a current timestamp that looks like this: 2011-11-01 10:34:24 Is
i have ajax function that looks like this: jQuery.ajax({ type: 'POST', data: { action:
I have data in a MYSQL DB that looks like this: id,parentid,name,count 1,0,top,10 2,1,middle1,5
I have a function that generates a random combination. my function looks like this:
I have a simple function that looks at an incoming mySQL data type and
I have a piece of code that looks like this: $result = mysql_query($queryc) or
I have a table with a row that looks like this: ( 20091231 48498429,
for SQL Server 2008 R2 I have a resultset that looks like this (note

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.