What is the best way to escape database INSERTS?
Permalink 1 user found helpful!@#$%^&*()"'
I've tried:
$db = Loader::db(); // Need to look into escaping //$grpName = $db->qstr($grpName); //$grpName = htmlspecialchars($grpName); $grpName = mysql_real_escape_string($grpName); // Create group $sql = "INSERT INTO goLabCollectionGroups VALUES('','$grpName','ENABLED','0');";
The only thing though that works for this is mysql_real_escape_string() which I've read should not be used. Can anyone help? The other two methods result in a mysql error.
Thanks!
AFAIK its adodbhttp://adodb.sourceforge.net/
...is what I do.
Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
$th = Loader::helper('text');
$db = Loader::db(); $db->Execute( 'INSERT INTO goLabCollectionGroup VALUES(?, ?, ?, ?)', array( '', $grpName, 'ENABLED', 0 ) );
adodb escapes for you. That above post was from when I was an idiot.
$db = Loader::db(); $vals = array(); $vals['column_name_a'] = "value"; $vals['column_name_b'] = "value"; $vals['column_name_c'] = "value"; $recordID = 1; $db->AutoExecute("tableName", $vals, "UPDATE", "id = $recordID");
Have a look here at the ADODB docs:
http://phplens.com/lens/adodb/docs-adodb.htm#autoexecute...
Hope this helps.
All the keys in the $data array, are your table columns and the values behind it the ones to be inserted. Assuming you're using 5.7.2 as you stated above that is.
i just found this post:
https://github.com/concrete5/concrete5-5.7.0/wiki/Migration-Guide#us...
Willing to take suggestions to improve this...