Fix images database query syntax
This was not updated when changing from oursql to pymysql in 10fcbf7.