Download the PHP package pyrsmk/olive without Composer

On this page you can find all versions of the php package pyrsmk/olive. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package olive

Olive 0.26.7

This library is now obsolete. Its successor is Olive2, a small wrapper around PDO.

Olive is a database library that aims to handle several databases with one simple API. It is designed for small to medium projects that don't need to be highly optimized because the API just supports the common tasks.

This project is a proof-of-concept and should be used as is.

Even if you can switch between different database types (like MySQL and MongoDB) with the same project and the same data structure, I do not encourage anyone to do it. Each database system has its own pros and cons and you should choose wisely what to use for your needs. Moreover, some methods on the API can be greedy, like join() with MongoDB which runs one additional request per join to retrieve data.

Please note that MongoDB is relation-less and should not be used with relational data structures.

Installation

Features

Create database connection

Creating a database connection works the same over all database adapters, it takes a database name as first argument and an array of options as second. Here's the available options for each database object :

MongoDB

MySQL

SQLite

Get data containers

A data container is an abstraction class for a table or a collection, per example. Data containers are the entry point to create queries. We can retrieve them with a simple call to :

If your table has a weird name, you can get it anyway with :

We strongly advise you to use namespaces in your applications so that your database is not pollute by random tables and avoid incompatibility issues between different applications/websites :

In Olive, you can specify a global namespace for simplicity :

If you need to remove the global namespace :

CRUD operations

The insert(), update(), save() and remove() are used for basic CRUD operations. These methods can accept an additional argument : an array of options for the driver. Please refer to the related PHP documentation pages (in PDO or MongoDB chapters) to have further information about it.

Querying

Searching & fetching

As you have seen, searches use a simple syntax to handle conditional operators. These operators are :

Take a look at how we're getting results :

The fetch() method retrieves all results. But there's other methods like fetchOne() which get the first row in the results and fetchFirst() that get the first field of the first row. Let's see a concrete example for that case :

There's also direct methods to search and retrieve in one call :

But please note that findFirst() is here for API consistency. Since we're not selecting any field, all of them are returned and the first field is often the ID of the row.

Of course, you can specify several searches in one request. Each search will be appended to the request with a AND operator.

Let's get a further look how searching works. In fact, each call to search() will be concatenated with AND operators. But we sometimes need to add an OR clause to the query. It is obtained by calling the orSearch() method :

All orSearch() clauses will be appended to the previous search.

Last note on this subject : calling search() returns a new Query object. It could happen that you need, per example, to do a loop and add a search at each cycle. In that case, you'll need to get a new query before calling search() :

Select fields & set aliases

With a SQL database, you could need to set aliases for several tables in your query to avoid conflicts :

Join

Sort

The sort() method takes the field and the sorting direction as arguments. The direction is either asc or desc.

Limit

Skip

Skipping results is useful when using limit() for pagination.

Count

For ease of use, you can directly count how many results that a search should return.

Create models

To simplify your models and have a nice object-oriented API, you can extend Olive\Model. The constructor takes an Olive object as argument and expects that $singular, $plural, $data_container and $primary_key class properties are well defined. Let's say we have a users table that we want to map, here's how we're defining it :

That's all we need for a simple model. But you often need specific queries to optimize things. You can just do it by adding a new method to your class, like getThoseFuckingWeirdResults().

Here's the exhaustive list of the methods you can natively call (replace singular and plural parameters by those you defined in your class) :

We should take a look at all those variables defined in the API. Most of them talk by themselves but not $search or $fields. The $search parameter is an associative array that lists the fields with the value to match for the query :

The $fields parameter is also an associative array that lists the fields to retrieve and maps aliases :

Advanced use

Last notes

License

Olive is released under the MIT license.


All versions of olive with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pyrsmk/olive contains the following files

Loading the files please wait ....