Empty or truncated table with RedBean PHP?

I use RedBean PHP for testing, and I really like it, but I have no idea how I can crop the table. I can get all the beans and remove them, but that seems cumbersome.

+3
source share
4 answers

In RedBean 1.3, you can use R :: wipe ($ type) to crop the table.

+6
source

RedBean is just an ORM tool (AFAIK), so if your base database is SQL based, you can simply execute the SQL statement, for example: TRUNCATE TABLE yourTable;

Fulfill queries directly through RedBean

Adapter

- , RedBean. . :

$adapter = $toolbox->getDatabaseAdapter();

http://www.redbeanphp.com/downloads/redbean.pdf - 1.3 http://www.redbeanphp.com/manual/manual.pdf - 2.0

+2

:

R::wipe($table);

MySQL :

function CleanAllTables() {
    $tables = R::getCol(' show tables ');
    foreach ($tables as $table) {
        R::wipe($table);
    }
}

MySQL

TRUNCATE TABLE <table_name>

RedBean

$adapter->exec('TRUNCATE TABLE <table_name>');

!:)

+1

, , , RedBean 4.0+ (, , ) , N-M .

So, in this case, in my case, to get around this, it was necessary to set the foreign key checks to 0.

R::exec('SET FOREIGN_KEY_CHECKS = 0;');
R::wipe('tablename');
0
source

Source: https://habr.com/ru/post/1778354/


All Articles