2015-05-14 101 views
1

我正在yii2中运行应用程序。我创建了一个命令控制器/命令/的TestControlleryii2 cron给出“找不到PDO”的错误

<?php 

namespace app\commands; 

use app\models\UserProfile; 
use yii\console\Controller; 
use app\controllers\AppController; 
/** 
* Test controller 
*/ 
class TestController extends Controller 
{ 

    public function actionIndex() 
    { 
     echo "cron service running"; 
    } 

    public function actionSendBirthdaySms() 
    { 
     $userProfile = UserProfile::find() 
      ->where('MONTH(dob) = MONTH(DATE(NOW()))') 
      ->andWhere('DAY(dob) = DAY(NOW()) ') 
      ->with('user') 
      ->asArray() 
      ->all(); 

     foreach($userProfile as $item){ 
      $birthdayMessage = "Happy Birthday " . $item['user']['username']; 
      //to send sms 
      $this->_send_cron_sms($item['mobile'], $birthdayMessage); 
     } 
    } 

我有两个功能在这里。当我打电话给php /home/user/public_html/yii test/index时,它会给命令行和cron两者提供正确的输出。

但是当我运行php /home/user/public_html/yii test/send-birthday-sms时,它在ssh环境下运行命令行并且我正在接收SMS。但在cron中给错误。这里是我收到的电子邮件:

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} 

我也试过查询生成器,但它也没有帮助我。

回答

2

我已经在php.ini文件中添加这两种扩展解决问题

extension=pdo.dll 
extension=pdo_mysql.dll 

我已经问了同样的问题在Yii forum