DB Insert Record not working Moodle 2.9.3

DB Insert Record not working Moodle 2.9.3

by Dave Emsley -
Number of replies: 4

Hi there,

I'm afraid this may be a bit of a newbie error but I get the error:


Debug info: You have an error in your SQL syntax; check
 the manual that corresponds to your MySQL server version for the right 
syntax to use near 'limit) 
VALUES('TKInter','Snugg1','Snuggles','1448323200','0','1')' at line 1
INSERT INTO mdl_voucher_codes (course,vouchercode,vendor,date_issued,quantity,limit) VALUES(?,?,?,?,?,?)
[array (
0 => 'TKInter',
1 => 'Snugg1',
2 => 'Snuggles',
3 => 1448323200,
4 => 0,
5 => 1,
)]
Error code: dmlwriteexception

when writing to a database table with:

            print_object($record);
            $lastinsertid = $DB->insert_record('voucher_codes',$record,false);

Database table exists. Attributes are correct and correctly data-typed.

The Print_Object function prints the object so I can see that it's correct.  What have I done wrong please?


Cheers


Dave


Average of ratings: -
In reply to Dave Emsley

Re: DB Insert Record not working Moodle 2.9.3

by Sam Chaffee -
Picture of Core developers

My guess is that the problem is that LIMIT is reserved keyword in MySQL. I think you'll need to rename your field.

Average of ratings: Useful (1)
In reply to Sam Chaffee

Re: DB Insert Record not working Moodle 2.9.3

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Note, if you take the recommended route to define your tables by using XMLDB, then it will warn you about use of reserved words.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: DB Insert Record not working Moodle 2.9.3

by Dave Emsley -

Sometimes I wonder how I remember to breathe.

Thanks guys.


In reply to Dave Emsley

Re: DB Insert Record not working Moodle 2.9.3

by Igor Sazonov -

If you have changed DB structure, just purge cache because of DB is cached

Average of ratings: Useful (2)