SQL formatting method for WPDB
|Reported by:||DevaSatyam||Owned by:||anonymous|
Added a BuildSql method to wpdb. It works, more or less, like a sprintf but oriented towards SQL and WordPress. Escape character is ? followed by a letters indicating the type of data to be inserted and some options. It includes a ?t which adds the contents of $table_prefix. After the first argument, the SQL statement with the ?xxx placeholders, there can be any number of arguments which are inserted into the string as indicated by the datatype and options.
echo BuildSql('Insert into ?ttable (?s,?ns,?mi,?d,?ni,?i)','Something','',5,time(),0,null);
Insert into wp_table ('Something',null,5,'2006-05-15',null,0)
It contains a PhpDocumenter-style heading with all the options. I was not able to get this version of WP working so I copied the version I'm using on my production site and made some minor modifications to make it self-contained (not dependent on some other functions of mine) which I was unable to test, sorry.