P
P
Pavel Gogolinsky2014-07-14 17:26:50
Yii
Pavel Gogolinsky, 2014-07-14 17:26:50

How to use the console command to access the database in Yii?

The site works in the browser and there is a connection to the database.
I create a console command to execute it via cron.
1) In the protected folder I create the file cron.php

<?php
$yiic=dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'framework'.DIRECTORY_SEPARATOR.'yiic.php';
$config=dirname(__FILE__).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'console.php';
require_once($yiic);

2) In the config folder in the console.php file I copy all the lines from the main.php file
3) In the commands folder I create the todayCommand.php file
<?php
class TodayCommand extends CConsoleCommand
{
    public function run()
    {
        $note = new Note();
        $note-> visible = 0;
        $note->save(false);
    }
}

I get the error could find driver
https://yadi.sk/i/F-lnZO-_Waa7H
I use OpenServer

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question