-1

I use Prepared Statements mostly to prevent SQL injections. Now I also need to filter a ENUM type. But how should I use it in my prepared statements to maintain security?

I have a table of addresses and need to filter on the user's invoice addresses. How do I do that and keep the security? Or does it not matter?

Two options I can think of. "Invoice" in the array as a string.

public function getCustomerInvoiceAddresses($customerNumber)
{
    $query = 'SELECT contactPerson, company, street, zipCode, city, deliveryMethod 
                FROM address 
                where FK_customerNumber = ? 
                AND addressType = ?';
    $paramType = 'is';
    $paramValue = array(
        $customerNumber,
        "Invoice"
    );
    $invoiceAddressArray = $this->ds->select($query, $paramType, $paramValue);
    return $invoiceAddressArray;
}

Invoice in the SELECT

public function getCustomerInvoiceAddresses($customerNumber)
{
    $query = 'SELECT contactPerson, company, street, zipCode, city, deliveryMethod 
                FROM address 
                where FK_customerNumber = ? 
                AND addressType = "Invoice"';
    $paramType = 'is';
    $paramValue = array(
        $customerNumber
    );
    $invoiceAddressArray = $this->ds->select($query, $paramType, $paramValue);
    return $invoiceAddressArray;
}

Or should I pass the string "Invoice" when I call the function?

$invoiceAddresses = $customer->getCustomerInvoiceAddresses($customerNumber, "Invoice");
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Xtreme
  • 1,601
  • 7
  • 27
  • 59

1 Answers1

-1

If you are parsing the data and using prepare statements I don't believe that SQL injection can happen. So I would use the most flexible choice and use

$invoiceAddresses = $customer->getCustomerInvoiceAddresses($customerNumber, "Invoice"); rename the function to getCustomerAddresses