I am building a PHP class to handle database management, and I wondered if it was possible to build a method which could receive a string with a concatenated array as one variable.
For example, take a look at this simplified code:
class Database {
function __construct() {
// Connect to the database, code not shown
}
public function query($input) {
// Do something with the input so the string values are recognized ...
// and the array and its keys are converted into an SQL string.
// Code not shown...
mysql_query($processedInput);
return true;
}
}
So, ideally, if I run something like this ...
$db = new Database();
$db->query("UPDATE `table` SET " .
array("id" = "2",
"position" = "1",
"visible" = "1",
"name" = "My Name's John",
"description" = "This is neat!"
) . " WHERE `id` = '1'");
... PHP would generate, then run this SQL ...
mysql_query("UPDATE `table` SET `id` = '2', `position` = '1', `visible` = '1',
`name` = 'My Name\'s John', `description` = 'This is neat!' WHERE `id` = '1'");
I can do all of the nitty-gritty array conversion, but, for now, all I need is a way for PHP to break the input up into strings and arrays, then evaluate each one separately.
I would like to avoid passing multiple values into the method.