vendredi 7 août 2015

PHP PDO + Sqlite, show indexes on table

I'm trying to show the indexes on a table using sqlite and PHP.

The manual here ( http://ift.tt/1IZIT6H ) suggests:

.indexes ?TABLE?

However, using

$pdo->query('.indexes my_table');

Shows:

PDOException: SQLSTATE[HY000]: General error: 1 near ".": syntax error

Is it possible to execute these dot commands using PHP and PDO?

edit: example code:

    $this->pdo->query('DROP TABLE IF EXISTS test');
    $this->pdo->query('CREATE TABLE test (id INT PRIMARY KEY NOT NULL, col1 text NOT NULL, col2 text NOT NULL)');
    $this->pdo->query('CREATE INDEX col1 ON test (col1)');
    $result = $this->pdo->query('PRAGMA table_info(test);')->fetchAll(\PDO::FETCH_OBJ);
    print_r($result);

This does not show the indexes. The following errors:

    $this->pdo->query('DROP TABLE IF EXISTS test');
    $this->pdo->query('CREATE TABLE test (id INT PRIMARY KEY NOT NULL, col1 text NOT NULL, col2 text NOT NULL)');
    $this->pdo->query('CREATE INDEX col1 ON test (col1)');
    $result = $this->pdo->query('.indexes test')->fetchAll(\PDO::FETCH_OBJ);
    print_r($result);

Aucun commentaire:

Enregistrer un commentaire