从会话 ID 所在的两个表中获取 select 数据

Getting select data from two tables where session id

我的 SELECT 查询有问题。我基本上是想从两个不同的表中获取信息,我想要客户信息(订单)+ 客户产品(orders_products),我只想要该特定 ID 的信息。

两个表都有 user_id 列。

$conn = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME . ';charset=utf8', DB_USER, DB_PASS);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $conn->prepare("SELECT * FROM orders, orders_products WHERE `orders.user_id` = `orders_products.user_id` = :user_id");
$sth->bindValue(':user_id', $_GET['id']);
$sth->execute();
$result = $sth->fetch();
SELECT orders.*, orders_products.* FROM orders
JOIN orders_products on orders_products.user_id = orders.user_id
WHERE `orders.user_id` = :user_id;

希望对您有所帮助:)