How can I detect right db type?

wpdb->dbh is declared as protected property, you should not even have access to it, unless you are subclassing wpdb?

The only public property is wpdb->is_mysql which is just hardcoded for true and meant for detection of non–native database drop–ins.

So overall wpdb context is meant to be internal, you set up the connection and let it deal with the detail from that point.

I have no experience with triggers in WP context, but it sounds strange for arbitrary query to not just work in query() method. I would recommend to get to the bottom of that. It might be that issue is with query or something related and not WP call running it.

error code: 523