Presentation

Walousql is a DBMS (database management system) in PHP ready to use which does not require any other engine, software or extension. The data is directly stored in the same place as your scripts. So, you don't have to manage a heavy DBMS (ex. Oracle, PosgreSQL, MsSQL, MySQL or MariaDB) and their disadvantages :

  • DBMS maintenance
  • Security failures
  • Management of users and their permissions
  • Creation and modification of databases and tables
  • ...

Walousql therefore stores the data on your server in « text » type documents which are: neither in TXT format, nor in CSV format, nor in TSV format, nor in XML format, nor even in JSON format, but in ... PHP format !

The data is written using the PHP functions var_export and file_put_contents (or fopen, fwrite and fclose depending on the version of PHP).
The data is read using a simple include.
Thus, the data is saved completely in PHP while keeping its type.

Thanks to this very simple operation, Walousql is probably the simplest DBMS for PHP.
Walousql was developed and tested in PHP 7, but it must be compatible with PHP 4.2 and PHP 5.

Tests were performed with 45 column records. Without modifying the memory management, Walousql was able to add 166,827 records.

Its performance was compared to that of MySQL by adding the same records of 45 columns :

Comparaison MySQL walousql
Up to 1600 new registrations in 30 seconds, Walousql performs better than MySQL !

Walousql is therefore particularly suitable for scripts and websites not managing more than 2000 records.

Download

To download Walousql, go to the project's GitHub page or download the ZIP archive directly :

Go to the GitHub page Download the archive

Setup

The unpacked strong>walousql-master.zip document, you will find the following tree structure :

  • walousql (folder to copy to the server)
    • data (folder where the data is stored)
      • sampleTable.table.php (sample table)
    • src
      • walousql.inc.php (definition of the Walousql class)
  • README.md
  • sample.php

To use Walousql, simply copy the walousql folder to your server, directly at the root of your website, or to another folder (eg includes).

First steps

TTheoretically, Walousql can record any type (literally) of data. But since it is a DBMS, the data you will store will be an array (array()).

It is therefore important to remember the two types of tables in PHP :

  • Associative tables
  • Keyless index tables

Depending on the case, you will use one of these two types, which Walousql manages without problem

Associative tables

Associative arrays consist of a set of key => value pairs separated by commas.

Example
<?php
$products = array(
	'tomatoKey' => array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Vegetable',
	),
	'bananaKey' => array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
);

var_export($products);

var_export($products['tomatoKey']);

foreach ($products as $key => $product){
	echo $key . ' --> ' . $product['name'] . ' : ' .  $product['color'] . ' ' . $product['type'] . "\n";
}
?>
The above example will display :
array (
  'tomatoKey' => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Vegetable',
  ),
  'bananaKey' => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  'name' => 'Tomato',
  'color' => 'Red',
  'type' => 'Vegetable',
)

tomatoKey --> Tomato : Red Vegetable
bananaKey --> Banana : Yellow Fruit

Keyless index tables

Keyless index tables consist of a set of values ​​without specifying a key. It is PHP that will directly assign a key (0, 1, 2, etc.) to the values.

Example
<?php
$products = array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
);

var_export($products);

var_export($products[0]);

foreach ($products as $key => $product){
	echo $key . ' --> ' . $product['name'] . ' : ' .  $product['color'] . ' ' . $product['type'] . "\n";
}
?>
The above example will display :
array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Vegetable',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  'name' => 'Tomato',
  'color' => 'Red',
  'type' => 'Vegetable',
)

0 --> Tomato : Red Vegetable
1 --> Banana : Yellow Fruit

Premier script

After copying the walousql folder to the root, you can create the following script that adds products and reads them :

<?php
// Include the definition of the class walousql
include 'walousql/src/walousql.inc.php';

// Create new walousql object
$walousql = new walousql();

// Insert four items
$walousql->add(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Cucumber',
		'color' => 'Green',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Orange',
		'color' => 'Orange',
		'type' => 'Fruit',
		'calories' => 47,
	),
));

// Get all items
$res = $walousql->selectAll();

// Print the items
var_export($res);
?>
The above example will display :
array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
  2 => 
  array (
    'name' => 'Cucumber',
    'color' => 'Green',
    'type' => 'Vegetable',
  ),
  3 => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
    'calories' => 47,
  ),
)

PHP functions

About the examples

To illustrate the functions, examples are offered. For readability, the data accesses in writing and in reading are on the same scripts.
Obviously, the examples all work equally well on different scripts :

add.php :
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
$walousql->add(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));
?>
selectall.php :
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
$res = $walousql->selectAll();
var_export($res);
?>
selectall.php will display :
array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)


new walousql

Create a new Walousql object

Description

new walousql ( [mixed $dataPath] ) : object

Parameter
  • dataPath
    Folder containing the tables
    By default, the value of this parameter is walousql/data/
Example
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
?>
Example by imposing the folder containing the tables
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql('/var/www/data');
?>

getDataPath

Get the absolute path of the folder containing the tables

Description

getDataPath () : string

Example
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
$data_path = $walousql->getDataPath();
echo $data_path; // /var/www/html/my-website.com/walousql/src/../data/
?>

setTable

Call the table passed in parameter

Description

setTable ( string $table [,boolean $force = false] ) : boolean

Parameter
  • table
    Name of the called table
  • force
    Force table re-reading
    When setTable is called for the first time, walousql reads the table stored on the server. If setTable is called a second time in the same script, Walousql reads the table on the server again only if the value of this parameter is true.
Example
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
$res = $walousql->setTable('sampleTable');

echo $res; // 1
?>

getTable

Get the current table

Description

getTable () : string

Examples
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
$table = $walousql->getTable();

echo $table; // default
?>
Example after calling a table with setTable :
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
$walousql->setTable('sampleTable');
$table = $walousql->getTable();

echo $table; // sampleTable
?>

getTablePath

Get the absolute path of the current table

Description

getTablePath () : string

Example
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
$data_path = $walousql->getTablePath();

echo $data_path; // /var/www/html/my-website.com/walousql/src/../data/default.table.php
?>
Exemple après avoir appelé une table avec setTable :
<?php
include 'walousql/src/walousql.inc.php';

$walousql = new walousql();
$walousql->setTable('sampleTable');
$data_path = $walousql->getTablePath();

echo $data_path; // /var/www/html/my-website.com/walousql/src/../data/sampleTable.table.php
?>

add

- Associative table : it is recommended to use the set function.
- Keyless indexed table : add items.
The add function returns the table of keys for the $rows parameter in the table.

Description

add ( array $rows ) : array

Parameter
  • rows
    Item(s) to add
Example
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$res = $walousql->add(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));
var_export($res);

$res = $walousql->selectAll();
var_export($res);

$res = $walousql->add(array(
	array(
		'name' => 'Cucumber',
		'color' => 'Green',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Orange',
		'color' => 'Orange',
		'type' => 'Fruit',
	),
));
var_export($res);

$res = $walousql->selectAll();
var_export($res);
?>
The above example will display :
array (
  0 => 0,
  1 => 1,
)

array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  0 => 2,
  1 => 3,
)

array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
  2 => 
  array (
    'name' => 'Cucumber',
    'color' => 'Green',
    'type' => 'Vegetable',
  ),
  3 => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
  ),
)
Example avec two tables
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->setTable('types');
$types_keys = $walousql->add(array(
	array('name' => 'Fruit'),
	array('name' => 'Vegetable'),
));
var_export($types_keys);

$walousql->setTable('products');
$types_keys = $walousql->add(array(
	array(
		'name' => 'Banana',
		'id_type' => $types_keys[0],	// Key for 'Fruit'
	),
	array(
		'name' => 'Cucumber',
		'id_type' => $types_keys[1],	// Key for 'Vegetable'
	),
));
$products = $walousql->selectAll();
var_export($products);

$walousql->setTable('types');
$types = $walousql->selectAll();

foreach ($products as $product){
	echo $product['name'] . ' : ' . $types[$product['id_type']]['name'] . "\n";
}
?>
The above example will display :
array (
  0 => 0,
  1 => 1,
)

array (
  0 => 
  array (
    'name' => 'Banana',
    'id_type' => 0,
  ),
  1 => 
  array (
    'name' => 'Cucumber',
    'id_type' => 1,
  ),
)

Banana : Fruit
Cucumber : Vegetable

set

- Associative table : add new items or update thems if they already exist
- Keyless indexed table : update items. To add items, it is recommended to use the add function.
The set function returns the table of keys for the $rows parameter in the table.

Description

set ( array $rows [,boolean $erase = false] ) : array

Parameters
  • rows
    Item(s) to add or to update
  • erase
    In the case of updating an existing element, this parameter allows :
    - Update only the indicated columns : $erase = false
    - Completely reset the item : $erase = true
    By default, the value of this parameter is false
Example - associative table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$res = $walousql->set(array(
	'tomatoKey' => array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Vegetable',
	),
	'bananaKey' => array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));
var_export($res);

$walousql->set(array(
	'tomatoKey' => array(
		'type' => 'Fruit',
	),
));
$res = $walousql->selectAll();
var_export($res);

$walousql->set(array(
	'bananaKey' => array(
		'color' => 'Yellow or black',
	),
), true);
$res = $walousql->selectAll();
var_export($res);
?>
The above example will display :
array (
  0 => 'tomatoKey',
  1 => 'bananaKey',
)

array (
  'tomatoKey' => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  'bananaKey' => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  'tomatoKey' => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  'bananaKey' => 
  array (
    'color' => 'Yellow or black',
  ),
)
Example - keyless indexed table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$products_keys = $walousql->set(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));
var_export($products_keys);

$walousql->set(array(
	$products_keys[0] => array(	// Key for 'Tomato'
		'type' => 'Fruit',
	),
));
$res = $walousql->selectAll();
var_export($res);

$walousql->set(array(
	$products_keys[1] => array(	// Key for 'Banana'
		'color' => 'Yellow or black',
	),
), true);
$res = $walousql->selectAll();
var_export($res);
?>
The above example will display :
array (
  0 => 0,
  1 => 1,
)

array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  1 => 
  array (
    'color' => 'Yellow or black',
  ),
)

selectAll

Returns all the items of the table

Description

selectAll ( [array $order = null] ) : array

Parameter
  • order
    Classification order
Example - associative table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->set(array(
	'tomatoKey' => array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Vegetable',
	),
	'bananaKey' => array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));

$res = $walousql->selectAll();
var_export($res);

$res = $walousql->selectAll(array('name' => SORT_ASC));
var_export($res);

$res = $walousql->selectAll(array('type' => SORT_ASC, 'color' => SORT_DESC));
var_export($res);
?>
The above example will display :
array (
  'tomatoKey' => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Vegetable',
  ),
  'bananaKey' => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  'bananaKey' => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
  'tomatoKey' => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Vegetable',
  ),
)

array (
  'bananaKey' => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
  'tomatoKey' => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Vegetable',
  ),
)
Example - keyless indexed table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->set(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));

$res = $walousql->selectAll();
var_export($res);

$res = $walousql->selectAll(array('name' => SORT_ASC));
var_export($res);

$res = $walousql->selectAll(array('type' => SORT_ASC, 'color' => SORT_DESC));
var_export($res);
?>
The above example will display :
array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Vegetable',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Vegetable',
  ),
)

array (
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Vegetable',
  ),
)

selectByKey

Returns the element informed by the key passed in parameter
If no element corresponds to the key passed in parameter, selectByKey returns false

Description

selectByKey ( mixed $key ) : array

Parameter
  • key
    Key whose item we want to recover
Example - associative table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->set(array(
	'tomatoKey' => array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Vegetable',
	),
	'bananaKey' => array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));

$res = $walousql->selectByKey('tomatoKey');
var_export($res);

$res = $walousql->selectByKey('cucumberKey');
var_export($res);
?>
The above example will display :
array (
  'name' => 'Tomato',
  'color' => 'Red',
  'type' => 'Vegetable',
)

false
Example - keyless indexed table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->add(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));

$res = $walousql->selectByKey(0);
var_export($res);

$res = $walousql->selectByKey(10);
var_export($res);
?>
The above example will display :
array (
  'name' => 'Tomato',
  'color' => 'Red',
  'type' => 'Fruit',
)

false

filter

Find the items of a table like a array_filter in PHP

Description

filter ( callable $callback [, int $flag = 0 [, array $order = null]] ) : array

Parameters
  • callback
    The callback function to use
  • flag
    Flag determining what arguments are sent to callback :
    - ARRAY_FILTER_USE_KEY : pass key as the only argument to callback instead of the value.
    - ARRAY_FILTER_USE_BOTH : pass both value and key as arguments to callback instead of the value.
    Default is 0 which will pass value as the only argument to callback instead.
  • order
    Classification order
Example
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->add(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Cucumber',
		'color' => 'Green',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Orange',
		'color' => 'Orange',
		'type' => 'Fruit',
	),
));

echo "Vegetables : \n";
$res = $walousql->filter(function($value){
	return $value['type'] == 'Vegetable';
});
var_export($res);

echo "Fruits in alphabetical order : \n";
$res = $walousql->filter(function($value){
	return $value['type'] == 'Fruit';
}, 0, ['name' => SORT_ASC]);
var_export($res);
?>
The above example will display :
Vegetables : 
array (
  2 => 
  array (
    'name' => 'Cucumber',
    'color' => 'Green',
    'type' => 'Vegetable',
  ),
)

Fruits in alphabetical order : 
array (
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
  3 => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
  ),
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
)


deleteByKey

Deletes the item(s) informed by the key passed in parameter
If at least one item is deleted, selectByKey returns true
If no item corresponds to the keys passed in parameter, selectByKey returns false

Description

deleteByKey ( mixed $key ) : boolean

Parameter
  • key
    Key or keys array from which we want to delete the elements
Example - associative table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$res = $walousql->set(array(
	'tomatoKey' => array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	'bananaKey' => array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
	'cucumberKey' => array(
		'name' => 'Cucumber',
		'color' => 'Green',
		'type' => 'Vegetable',
	),
	'orangeKey' => array(
		'name' => 'Orange',
		'color' => 'Orange',
		'type' => 'Fruit',
	),
));

$res = $walousql->deleteByKey('bananaKey');
echo $res;

$res = $walousql->selectAll();
var_export($res);

$res = $walousql->deleteByKey(array('tomatoKey', 'cucumberKey'));
echo $res;

$res = $walousql->selectAll();
var_export($res);

$res = $walousql->deleteByKey('bananaKey');
echo $res;
?>
The above example will display :
true

array (
  'tomatoKey' => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  'cucumberKey' => 
  array (
    'name' => 'Cucumber',
    'color' => 'Green',
    'type' => 'Vegetable',
  ),
  'orangeKey' => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
  ),
)

true

array (
  'orangeKey' => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
  ),
)

false
Example - keyless indexed table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->add(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Cucumber',
		'color' => 'Green',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Orange',
		'color' => 'Orange',
		'type' => 'Fruit',
	),
));

$res = $walousql->deleteByKey(1);
echo $res;

$res = $walousql->selectAll();
var_export($res);

$res = $walousql->deleteByKey(array(0, 2));
echo $res;

$res = $walousql->selectAll();
var_export($res);

$res = $walousql->deleteByKey(10);
echo $res;
?>
The above example will display :
true

array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  2 => 
  array (
    'name' => 'Cucumber',
    'color' => 'Green',
    'type' => 'Vegetable',
  ),
  3 => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
  ),
)

true

array (
  3 => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
  ),
)

false

deleteAll

Remove all items from a table
If items are deleted, deleteAll returns true
If the table was already empty, deleteAll returns false

Description

deleteAll ( [boolean $destroyTable = false] ) : boolean

Parameter
  • destroyTable
    Force to completely destroy the table.

    This parameter is only useful in the case of keyless index table :
    - If destroyTable is false, the keys of the added items will increment following the deleted items.
    - If destroyTable is true, the keys of the added items will start again at 0.
Example - associative table
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$res = $walousql->set(array(
	'tomatoKey' => array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	'bananaKey' => array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));

$res = $walousql->deleteAll();
echo $res;				// true

$res = $walousql->selectAll();
var_export($res);		// array()

$res = $walousql->deleteAll();
echo $res;				// false
?>
Example - keyless index table - destroyTable = false
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->add(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));

$res = $walousql->selectAll();
var_export($res);

$walousql->deleteAll();

$walousql->add(array(
	array(
		'name' => 'Cucumber',
		'color' => 'Green',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Orange',
		'color' => 'Orange',
		'type' => 'Fruit',
	),
));

$res = $walousql->selectAll();
var_export($res);
?>
The above example will display :
array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  2 => 
  array (
    'name' => 'Cucumber',
    'color' => 'Green',
    'type' => 'Vegetable',
  ),
  3 => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
  ),
)
Example - keyless index table - destroyTable = true
<?php
include 'walousql/src/walousql.inc.php';
$walousql = new walousql();

$walousql->add(array(
	array(
		'name' => 'Tomato',
		'color' => 'Red',
		'type' => 'Fruit',
	),
	array(
		'name' => 'Banana',
		'color' => 'Yellow',
		'type' => 'Fruit',
	),
));

$res = $walousql->selectAll();
var_export($res);

$walousql->deleteAll(true);

$walousql->add(array(
	array(
		'name' => 'Cucumber',
		'color' => 'Green',
		'type' => 'Vegetable',
	),
	array(
		'name' => 'Orange',
		'color' => 'Orange',
		'type' => 'Fruit',
	),
));

$res = $walousql->selectAll();
var_export($res);
?>
The above example will display :
array (
  0 => 
  array (
    'name' => 'Tomato',
    'color' => 'Red',
    'type' => 'Fruit',
  ),
  1 => 
  array (
    'name' => 'Banana',
    'color' => 'Yellow',
    'type' => 'Fruit',
  ),
)

array (
  0 => 
  array (
    'name' => 'Cucumber',
    'color' => 'Green',
    'type' => 'Vegetable',
  ),
  1 => 
  array (
    'name' => 'Orange',
    'color' => 'Orange',
    'type' => 'Fruit',
  ),
)

Manual management

The walousql/data/ folder (or the $dataPath specified by in new walousql()) contains the tables. Each document in this folder corresponds to a table. The documents end with ".table.php".
You can perform several operations on the tables by manipulating these documents :

  • To delete the sampleTable table, delete the document sampleTable.table.php
  • To delete and save the sampleTable table, rename the document sampleTable.table.php to SampleTable-bak.table.php
  • To rename the table sampleTable to newSampleTable, rename the document sampleTable.table.php to newSampleTable.table.php
  • To add, delete or modify items of the sampleTable table, edit sampleTable.table.php

Who uses Walousql ?

Les Tontons du Net

Have you chosen to use Walousql for your website ?

Please let us know by sending an email to : support@kaixo.fr