Download the PHP package aslamhus/db without Composer

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

DB

A Database class for mysqli prepared statements. Connect to your database and easily prepare statements, bind variables and execute queries. Currently Has methods for MYSQL select, insert, update and delete.

Install

Dependencies

  1. Composer
  2. composer package "vlucas/phpdotenv"
  3. MYSQL database with access privileges
  4. PHP

Getting started

Configuring your database

DB configures your database settings using environment variables. To set those up you'll need to install vlucas/phpdotenv and create a .env file with your database name, host, username and password.

1. Install

If you have cloned the repo, install all dependencies.

If you are installing @aslamhus/db as a package, simply run

You should now have vlucas/phpdotenv in your vendor directory. More information on vlucas/dotenv

2. Create .env file in your project root directory with the following variables

3. Load your environment variables

create a config.php file with the following:

Make sure you specify your path to vendor/autload and your .env file

4. Connect to the database

Require your config.php file and then instantiate the DB class.

That's it! You should now be connected to your database. You can begin making queries.

Optional: Allowlist for table names and columns

If you would like to add an extra layer of security, you can create an allow list of valid table names and valid column names in your mysql queries.

Create two text files in the src directory, '.validcolumns' and '.validtables' Separate names of valid tables and valid columns by line breaks. DB will then only perform queries on valid columns or tables. If the files are left blank or do not exist, all tables and all columns will be allowed.

Testing

To see DB in action you can run test/index.php in a local environment with mysql and php installed.

Before running these examples you'll need to set up a test database.

  1. Login to your local mysql with admin privileges
  2. create a test database/test table by executing test/db/schema.sql
  3. add values to your test database by executing seeds.sql

Now you can run test/index.php in your local environment.

Examples

select

select takes two parameters with an optional third. The first parameter is the columns to select, the second is the tablename and the third is an optional array of conditions.

Select everything

Select with conditions

In this example we select everything from the table 'users' where a the username has a value of the variable $username.

... more examples to come!

Author

aslamhus


All versions of db with dependencies

PHP Build Version
Package Version
Requires vlucas/phpdotenv Version ^5.4
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 aslamhus/db contains the following files

Loading the files please wait ....