'MySQL join from two different tables from different databases [duplicate]
I have created a MySQL join between two tables in two different databases on our account. The query works fine on my local server, but the host server doesn't like it. How can I make a connection to the second database, so the query works? Below is the error message with my code below that.
Query failed SQLSTATE[42000]: Syntax error or access violation: 1142 SELECT command denied to user 'someone'@'localhost' for table 'products'
Query
try {
$getPurch_info = $conn->prepare("
SELECT M.carrier, M.order_number, M.serial_number, M.tracking,
M.carrier, M_2.model FROM myDB_beta.purchases AS M
JOIN myDB2.products AS M_2 ON
M.product_ID = M_2.product_ID WHERE M.product_ID = ?");
$getPurch_info->execute(array($product_ID));
} catch (Exception $ex) {
die();
}
Solution 1:[1]
I think on your local server you have both databases on a single machine and you use "root" as user which has access to both of the databases.
On the live server your problem should be a task for you dev-ops / sysadmin. He must configure a database user which has access to both databases.
You should do the PDO connect like this:
$conn = new PDO('mysql:host=your_host', your_user, your_pass);
And after in the SQL you must name the database directly, not with aliasses.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |