Download the PHP package elbucho/database without Composer

On this page you can find all versions of the php package elbucho/database. 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 database

elbucho/database

This project provides a utility wrapper around PDO requests for MySQL. It allows you to lazy-load multiple different database connections in one callable object, and gives you a streamlined access to PDO's methods.

Configuration

The Database class is instantiated by passing it an Elbucho\Config object with one or more DSNs in it. See the elbucho/config documentation for instructions on how to place and read in your config files.

DSNs

Database connections must be stored in the "dsns" key of your Config object, and each must have the below required keys. You can include multiple connections in one Config object.

The required keys for each database connection are:

Additionally, the optional key "port" can be specified with the port number your database server is running on. This defaults to 3306.

Default Handle

If your config file only contains information for one database connection, the Database object will set the handle for this connection to "default". If you have multiple connections, each connection must be prefaced with the handle name for that connection.

You can override the default handle name by specifying a 'default_handle' key in your config:

Below are two sample .yml files. This first one shows a singular connection, and it will be automatically assigned the default handle.

This .yml file shows multiple connections (eg. a dev and production db server):

This will create two handles in the $database object: "dev" and "prod".

Querying the Database

Once your config file is set, you can instantiate a database object and query it in one of two ways:

$database->query():

This method takes up to 3 arguments: your query itself, any parameters you wish to pass to the MySQL engine, and the handle to query (defaults to "default"). It returns an array of results or throws a \PDOException if there was an issue with the query.

$database->exec():

This method takes the same 3 arguments as query(), but does not return results. It is useful for passing commands to MySQL that you do not require a return for:

Fetching last insert ID

If you've just inserted a row or rows into your database, you can get the last insert id by typing:

Again, if the handle is left out, it will use whatever your default handle is set to.

Fetching the number of rows affected by the previous query

If you've just updated / inserted / deleted one or more rows in your database, you can get the count of rows affected by using:

Similar to getLastInsertId(), if you leave out the handle, it will use whatever your default handle is set to.

Setting Attributes

You can set PDO attributes on a given connection via the setAttribute method. This works identically to the PDO setAttribute method, with the exception that a handle is also passed:


All versions of database with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
doctrine/inflector Version ^1.0
pds/skeleton Version ^1.0
elbucho/config Version *
ext-pdo Version *
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 elbucho/database contains the following files

Loading the files please wait ....