We present improved constraints on the coupling of ultralight bosonic dark matter to photons based on long-term measurements of two optical frequency ratios. In these optical clock comparisons, we relate the frequency of the 2S1/2(F=0)↔2F7/2(F=3) electric-octupole (E3) transition in 171Yb+ to that of the 2S1/2(F=0)↔2D3/2(F=2) electric-quadrupole (E2) transition of the same ion, and to that of the 1S0↔3P0 transition in 87Sr. Measurements of the first frequency ratio νE3/νE2 are performed via interleaved interrogation of both transitions in a single ion. The comparison of the single-ion clock based on the E3 transition with a strontium optical lattice clock yields the second frequency ratio νE3/νSr. By constraining oscillations of the fine-structure constant α with these measurement results, we improve existing bounds on the scalar coupling de of ultralight dark matter to photons for dark matter masses in the range of about 10−24−10−17eV/c2. These results constitute an improvement by more than an order of magnitude over previous investigations for most of this range. We also use the repeated measurements of νE3/νE2 to improve existing limits on a linear temporal drift of α and its coupling to gravity.