SELECT i.id as id, i.image, i.link as link
				  
		  FROM images i 
		  INNER JOIN pages p ON i.page_id = p.id
		  WHERE p.status != 'deleted'
		  AND p.relation_id = 
		  AND p.category = 'bgr_photo'
		  ORDER BY RAND()
		  LIMIT 1
		  

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND p.category = 'bgr_photo'
		  ORDER BY RAND()
		  LIMIT 1' at line 7

file -
line -