开发者

Write dynamic INNER JOIN in PDO

I want to write a dynamic function for INNER JOIN in pdo. I want send table name and condition to function and create dynamic query in function.

SELECT *  
FROM :tbl 
INNER JOIN :tbl2 ON :tbl1.id =开发者_如何转开发 :tbl2.id 
WHERE :tbl2.id  = :value;

I want to passed tbl, tbl2, tbl.id, tbl2.id, and WHERE condition to function and create dynamic query and biindParam with PDO then execute query.

How can I write this function?


you can't bind identifiers. So, table and field names should be added into query directly.

However, if you need such a dynamic join, it's most likely because your database setup is wrong.
And you'd better normalize it. So, you will have more reliable database yet will be no need in such dynamical joins

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜