Create a MySQLi connection

 * Create a MySQLi connection 
 * and fetch data from a table.

// Set host and credentials.
$host = '';
$database = 'db';
$user = 'user';
$password = 'pass';

// Create and check connection.
$connection = mysqli_connect($host, $user, $password, $database);
  exit('Could not establish connection ' . mysqli_connect_error());

// Create a simple query.
$items = $connection->query('SELECT * FROM table');

// See number of items to handle.
print 'Number of items fetched: ' . $items->num_rows;

Install CouchDB on Ubuntu

CouchDB can be installed by typing the following command in command line:

sudo apt-get install couchdb

​You can see if CouchDB is installed properly by typing sudo service couchdb status in command line.


Once CouchDB is installed, a web interface is available on http://localhost:5984/_utils/

Install SQLite on Ubuntu

SQLite can be installed by typing the following command in command line:

sudo apt-get install sqlite3 libsqlite3-dev

You can see if SQLite is installed properly by typing sqlite3 in command line.


Quit SQLite by typing .exit.

Help is on the way when typing .help.


Drop MongoDB database in PHP

// Establish connection.
$connection = new Mongo();

// Select database.
$database = $connection->demo;

// Drop database.
$dropped = $database->drop();

// Close connection.

First steps using MongoDB in PHP

// Establish connection.
$connection = new Mongo();
// Select database, create database if database not exists.
$database = $connection->demo;
// Select collection.
$collection = $database->users;
// Insert data.
$user = array(
  'name' => 'Dribbit',
  'email' => '',

// Get all records.
$records = $collection->find();
foreach($records as $record) {

// Close connection.

Where does mongodb stores data

Type following command in command line terminal:

sudo nano /etc/mongodb.conf



This is based on an Ubuntu system.

Install MongoDB driver for PHP on Ubuntu

Type following line in command line:

sudo pecl install mongo

If Pecl throws this error: configure: error: sasl.h not found! add following command and retry installing mongodb

sudo apt-get install libsasl2-dev

After installing, add the mongo extension to php.ini

Restart apache:

Install MongoDB on Ubuntu

32 bit systems are limited to DB of 2 gig. Therefor, use MongoDB only on 64 bit systems in production.

@see MongoDb documentation to install MongoDB.

See if MongoDB is running by typing

sudo service mongodb status

in command line.



Subscribe to RSS - Database