Reputation: 25
I'm trying to select all the results from a table A and all results from table B
I used this Request:
$request_public_imgs = $BDD-> query("SELECT * FROM images_public ");
UNION("SELECT * FROM images_users WHERE img_kind='PublicImg' ")
;
But I receive this error
Fatal error: Call to undefined function UNION()
Upvotes: 0
Views: 20657
Reputation: 206
Write your SQL command as a single piece :
$request_public_imgs = $BDD-> query("SELECT id, field1, .. FROM images_public
UNION SELECT id, field1, .. FROM images_users WHERE img_kind='PublicImg' ") ;
You should select precise field and not using * for performance matter. Adrien
Upvotes: 4
Reputation: 862
try this
$request_public_imgs = $BDD-> query("SELECT * FROM images_public
UNION SELECT * FROM images_users WHERE img_kind='PublicImg' ")
;
Upvotes: 0
Reputation: 290525
UNION
is a MySQL
function, hence you need to put it inside the query()
:
$request_public_imgs = $BDD-> query("
SELECT * FROM images_public
UNION
SELECT * FROM images_users WHERE img_kind='PublicImg' ");
More generally, all the queries will work like:
$request_public_imgs = $BDD-> query("YOUR_MYSQL_QUERY");
Note that the error Fatal error: Call to undefined function UNION()
was warning about UNION
not being a function of PHP.
Upvotes: 3