Fix segmentation fault that an empty prepared statement could cause.

Back-patch to all supported branches.

Per bug #11335 from Haruka Takatsuka