PDO error in Yii2 cron job

I am building an application on Yii2 framework. I need to create a cron job to automatically send birthday and anniversary SMS. I started writing code in Commands/TestController and its working fine in command line on my windows PC. Also I have SSH access and code is running there as well. I have received the SMS. Here is the command:


30 04 * * * php /home/user/public_html/yii test/send-birthday-sms

But problem is, when I apply same command over cron job in cPanel, then it doesn’t work and gives me ‘PDO not Found’ error in email. Here is what I receive in email:


Status: 500 Internal Server Error

X-Powered-By: PHP/5.4.39

Content-type: text/html

PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'PDO' not found'

in /home/user/public_html/vendor/yiisoft/yii2/db/Connection.php:609

Stack trace:

#0 [internal function]: yii\base\ErrorHandler->handleFatalError()

#1 {main}

I have researched a lot on internet about this but did not get any close answer. Already post this in SO but did not get any answer so I decided to post here. Since this is my first post here so I am not able to post link.

Check if your CLI php.ini is set with PDO just like your CGI one.

do one thing share your testcontroller code and config of console folder.

Here is the code:

<?php

namespace app\commands;

use app\models\UserProfile;

use yii\console\Controller;

use app\controllers\AppController;

class TestController extends Controller

{

public function actionSendBirthdaySms()


{


    &#036;userProfile = UserProfile::find()


        -&gt;where('MONTH(dob) = MONTH(DATE(NOW()))')


        -&gt;andWhere('DAY(dob) = DAY(NOW()) ')


        -&gt;with('user')


        -&gt;asArray()


        -&gt;all();


    foreach(&#036;userProfile as &#036;item){


        &#036;birthdayMessage = &quot;Happy Birthday &quot; . &#036;item['user']['username'];


        //to send sms


        &#036;this-&gt;_send_cron_sms(&#036;item['mobile'], &#036;birthdayMessage);


    }


}

}

?>

where is db configuration code?

its my config/console.php code:

<?php

Yii::setAlias(’@tests’, dirname(DIR) . ‘/tests’);

$params = require(DIR . ‘/params.php’);

$db = require(DIR . ‘/db.php’);

return [

'id' =&gt; 'basic-console',


'basePath' =&gt; dirname(__DIR__),


'bootstrap' =&gt; ['log', 'gii'],


'controllerNamespace' =&gt; 'app&#092;commands',


'modules' =&gt; [


    'gii' =&gt; 'yii&#092;gii&#092;Module',


],


'components' =&gt; [


    'cache' =&gt; [


        'class' =&gt; 'yii&#092;caching&#092;FileCache',


    ],


    'log' =&gt; [


        'targets' =&gt; [


            [


                'class' =&gt; 'yii&#092;log&#092;FileTarget',


                'levels' =&gt; ['error', 'warning'],


            ],


        ],


    ],


    'db' =&gt; &#036;db,


],


'params' =&gt; &#036;params,

];

?>

these are the default values. I did not changed anything in this file.

I am using YIi2 basic template.


30 04 * * * php /home/user/public_html/yii test/sendBirthdaySms

use this

and also check what BIZLEY replied.

I used this command but its giving me error on both ssh and cron. And also I checked PHP version using ‘php -v’ its PHP 5.4.39 (cli) (built: Apr 17 2015 11:53:42)

it gives u same PDO error?

No, it gives following:




X-Powered-By: PHP/5.4.39

Content-type: text/html

Error: Unknown command "test/sendBirthdaySms".

I also posted this on SO 4 days back,

In my case, cron is successfully running in yii2 advanced application where functionality to send mail to admin.

$this->_send_cron_sms($item[‘mobile’], $birthdayMessage);

it seems issue with above function.

Thanks I will look into it. I am using Yii basic template, if there is any issue?

The problem is with PDO not with _send_function_sms function.

I ll try to solve ur problem if gets host details or else no idea.:(

I can not give you host details as the website is running live. its not in my hand, sorry bro.

how would I check CGI version. I checked php -v it gives me PHP version 5.4.39 (cli)

Check this one http://askubuntu.com/questions/356968/find-the-correct-php-ini-file

I have solved the issue by adding following extensions in php.ini file

extension=pdo.dll

extension=pdo_mysql.dll

And its working nice.

Thanks everyone for participating.

have one question how ur other code running nicely?