I was an old school using mysql_query and starting to use PDO. It's great!
But in my old scripts, I built a dynamic query builder, and I have a hard time porting this to using PDO.
If someone can give me some direction, it will be great!
Here is the theory of this.
- I have an array
- Fields and values โโof the database (after insertion).
- Create a query string to get a valid PDO transaction
Here is part of what I'm trying to do.
public $dbFields; // This is an array of the fields plus VALUES public function select($where, $limit) { // This is what I **had** before $query = "SELECT ". implode(", ", $this->dbFields) ." FROM ". $this->table." WHERE ". $where ." ". $limit.""; // Now i need to convert that to PDO $this->connection->beginTransaction();
This is what I had before
$results = $db->select("userId = 111 OR userId = 222");
But what I'm thinking I need to do something more like
$results = $db->select(array("userId"=>111, "userId"=>222));
I know this is a high order, and I hope it makes sense in what I'm trying to do, but any help in trying to build these queries would be greatly appreciated.
source share