Bhupal Sapkota Software Consultant Helping founders build
and launch their ideas with code & AI

Bhupal's Newsletter

I send out occassional email with programming resources, summaries of my readings on art, science, and commerce behind technology, my writings on growing an online business etc. Feel free to subscribe, no spam!

Home

Building Dynamic Queries in PHP MySQL PDO

1. When you need a dynamic Search Query where variable parameters are presents you can use the following approach: $sql = “SELECT * FROM users WHERE “; $where = array(“dist_id = :dist_id”); $params = array(‘:dist_id’ => $distID); if (isset($p->username) && !empty($p->username)) { array_push($where, “username LIKE :username”); $params[‘:username’] = “%{$p->username}%”; } if (isset($p->firstname) && !empty($p->firstname)) { […]

Tagged with: