Custom PHP script throws critical error ONLY when editing page

When you’re editing the page, you’re in the directory wp-admin, and wp-admin doesn’t contain wp-content (they’re both children of your site’s root directory).

Instead of 'wp-content/uploads/cams/', I’d recommend ABSPATH . 'wp-content/uploads/cams/' which should work wherever you might be in the WordPress environment.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)