I've been reading a PHP book on design patterns and would like to incorporate one of their database patterns in my code. Specifically,the class method returns an an array with two elements within it.
The first element is a string looks like this.
"SELECT col1, col2, col3 FROM table WHERE col1 = ?, col2= ?"
The second element is an array which contains an array of string values (in this case 1 and 2)
I am looking for the most efficient way(it will be used quite often to instantiate objects) to merge these two arrays on the "?" delimiter so that the end result is a string which = "SELECT col1, col2, col3 FROM table WHERE col1=1, col2=2"
I've seen stuff such as preg_replace, but that relies on a fixed N array of patterns. I'm looking for something a little more dynamic. I will use the output of the code in a PDO select statement. Note that the above is a specific example, but that I need it to work for arbitrary amount of ? and inputs
Here is the code
//This function returns an array of two elements, $string_ar[0] is the string, $string_ar[1] are the values
$string_ar = $selectionFactory->doNewSelection($friend_idobj,'has_friend');
Thanks everyone!