#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    Error when call store procedure in codeigniter


    I have simple store update

    DELIMITER $$

    CREATE PROCEDURE update_post($post_id int(11),$title varchar(100))
    BEGIN

    set @query=concat('update tbl_posts set title=', $title));

    set @where=concat(' where id=',$post_id);

    set @query=concat(@query,@where);

    prepare stmt from @query;
    execute stmt ;
    deallocate prepare stmt;

    END

    and I call it in codeigniter: $this->db->query('call update_post($post_id,$title)') but it working when $title is only a word and without any blank space, someone help me pls

    Thank for reading my topic
    example : title
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,027
    Rep Power
    4210
    change this --
    Code:
    set @query=concat('update tbl_posts set title=', $title));
    to this --
    Code:
    set @query=concat('update tbl_posts set title=''', $title, ''''));
    r937.com | rudy.ca
    please visit Simply SQL and buy my book
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0
    can you explain more my error, thank
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,027
    Rep Power
    4210
    Originally Posted by mrfreedom
    can you explain more my error, thank
    sure

    you need to enclose strings in quotation marks
    r937.com | rudy.ca
    please visit Simply SQL and buy my book
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0
    thank you sir,I lost many hour for this problem and now it ok I can save my time,

    god bless to you

IMN logo majestic logo threadwatch logo seochat tools logo