php - Prepared Statement with inner join, on multiple databases at the same time -
i sure has been answered, if know where.
databases
have 2 databases "conn" , "conn2"
conn host table called account. account has 2 columns: user_key,username
conn2 has table called miles miles has 3 columns: miles_key,miles_user_key, miles_amount
what create leader board.
i pull miles_amount conn2 , use sum function total value. while using inner join on miles_user_key = user_key username conn.
i can fine , dandy single database, have no clue on how dual databases.
$lb_user_query = " select miles_user_key, username, sum(miles_amount) 'miles' miles inner join account on account_stats.account_stats_account_key = miles.miles_user group miles.miles_user order miles desc"; $lb_user_stmt = $conn->prepare($lb_user_query); $lb_user_stmt->execute(); $lb_user_stmt->bind_result($miles_user_key, $username, $miles);
on side note, if wondering why account, , miles in 2 separate databases because have 2 separate sites same accounts populating each..
to pull data seperate databases, prepend table name database name. instead of using account
, use conn.account
, , instead of miles
, use conn2.miles
.
Comments
Post a Comment