I solved my problem.
In order to load wp-db.php there are some prerequisites in WordPress 4.0. They are as follows:
define('WPINC','public_html/wp-includes');
define('WP_USE_THEMES', false);
define('FROM_CRON',true);
wp-config.php
wp-includes/version.php
wp-includes/plugin.php
wp-includes/functions.php
wp-includes/load.php
wp-includes/wp-db.php
$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
….
FROM_CRON is used to stop loading wp-settings.php when called from the cron job. It is used in config.php as:
if ( !( defined(‘FROM_CRON’) && FROM_CRON ) ) require_once(ABSPATH . ‘wp-settings.php’);
Now I can run my script as a cron job without any problems.
ahmet aksoy