How to avoid sql injection when running a native sql query with parameter input?
e.g.
$sql = "Select * from eav_attribute where attribute_id = {$attribute_id} ";
$result = $this->_connection->fetchRow($sql);
How to avoid sql injection when running a native sql query with parameter input?
e.g.
$sql = "Select * from eav_attribute where attribute_id = {$attribute_id} ";
$result = $this->_connection->fetchRow($sql);
The most correct answer is "don't directly query the database" - you should be using the ORM which would protect you in these situations. Especially when grabbing data out of the EAV tables.
The longer answer is that to do this safely you need to bind the query parameters to the query with Zend_Db_Select
's bind rather than using a full SQL statement:
$query = $this->_connection->select()->from('eav_attribute')->where('attribute_id=?', $attributeId);
$result = $this->_connection->fetchAll($query);
For more information see answers like this: https://magento.stackexchange.com/a/103038/336