简体   繁体   中英

Select two tables in one query PDO

I'v spent already a few hours to figure out this query but no result,

I'm actually new in PDO I used to do MYSQL but I saw here on stackoverflow that I have to change to PDO because MYSQL will be disabled soon,

So now to my question, I want to select two different tables with no relations one to other in one query like this,

$query = $dbh->query("SELECT * FROM table1; SELECT * FROM table2");
//rest of query,

How do I do that?

就像使用香草SQL一样:

$query = $dbh->query("SELECT * FROM table1, table2");

Or use JOIN

SELECT t1.id, t2.name FROM users AS t1 JOIN persons AS t2 ON t1.id = t2.id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM