Question

Hi I've got a sqlite2 database that is being used by a PHP webapp and I want a Yii webapp to access it. At the moment I copied the db file to a local server and I've changed config/main.php to:

        'db'=>array(
        'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/thedatabase.db',
    ),

When I run the Gii model generator I get:

CDbException

CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]: General error: 26 file is encrypted or is not a database. The SQL statement executed was: SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'

BTW I am able to convert the database to SQL using

Exporting sqlite2 database to SQL

Though I want the database to stay as an sqlite2 database so that the Yii app can access up to date user info.

Was it helpful?

Solution 2

I got it working with the sqlite2 database by using 'sqlite2:' instead of 'sqlite:'

'db2'=>array(
            'class'=>'CDbConnection',
            'connectionString' => 'sqlite2:'.dirname(__FILE__).'/../../../thedatabase.db',
),

I can do queries like this:

Yii::app()->db2->createCommand($sql)->queryAll());

To stop Error 500 Object configuration must be an array containing a "class" element 'class'=>'CDbConnection' is required in config/main.php. I think that info is already included in the first database connection somewhere.

OTHER TIPS

After some thought it looks like it would be simpler to just use some code from the old PHP project in the Yii project...

$db = sqlite_open($databasefilename, 0666, $sqliteerror);
$query = sqlite_query($db, "SELECT password FROM user WHERE username='$username'");
$row = sqlite_fetch_array($query);
if ($row) {
    return $row[password];
}

Edit: When using that code I get the following error: undefined function sqlite_open()

I'm using PHP Version 5.4.7...

http://au1.php.net/manual/en/function.sqlite-open.php

Here it says: PHP 5 < 5.4.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top