Download the PHP package azaddevx/database without Composer

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

AzadSqlBanner

MySQL PHP

GitHub issues GitHub version

packagist Github all releases MIT license

1. Introduction

One of the main goals of the project is to establish a connection with the database in a way that maintains clean code structure while ensuring program speed, despite the use of various automated capabilities and tools. Additionally, employing object-oriented methods in different parts of the project improves team productivity and helps team members gain full mastery in various project areas.

It’s worth noting that this project is still in the testing and debugging phase, and we invite programmers to join us in its development.

2. how does it work

This is a developing library for interacting with databases (currently only MySQL). The library can automatically encrypt data, sort it, and also execute Query commands through job definitions without losing information or making unilateral changes.

3. Basic rules

Folder Setup: First, you need to create a folder structure for your project. This folder should include files related to tables, encryption, builders, and other necessary components. Make sure to configure this folder properly. Project Namespace: Alongside configuring the folder, the project name (defined in the configuration class) should serve as a namespace for your project files. This ensures that your project remains organized and that different components can be easily associated with the project.

for example:

Remember that this project is still in the testing and debugging phase, so it’s essential to collaborate with fellow developers to enhance its functionality. If you have any further questions or need assistance, feel free to ask!

4. Initial Setup

First, install the azaddevx/database library using Composer. To do this, run the following command in your terminal:

Next, load the library using the autoload.php file:

Now, to begin, you need to create a configuration class. The components of the configuration are explained below.

After creating this class, pass it directly to the Connect class.

Database: In this section, enter the database connection information. In the future, depending on the type of database you have, the information set for this feature may differ. Currently, this feature includes four elements named as follows:

host: Your database host

username: The username used for connection

password: Your database password

name: The name of the database you intend to connect to

Project: In this section, your project information including the project name, project folder, etc., is set up

which includes two elements: directory and name

Table: This feature contains the general settings related to the data table. Currently, it includes an element named prefix. The prefix of the data table can essentially serve as a signature for all data tables, placed before the actual name and separated from the main table name by an underscore (_).

Log: This feature is useful when you are debugging your project. The logs save all the operations performed by the library in an insecure file (you must handle the security settings yourself), and you can view the commands executed by the library. It includes the following three elements:

System: This feature pertains to the main system of the library, which includes two elements: RAM and Database.

RAM: This feature stores the data received from the database in the system’s RAM, eliminating the need for resending queries to retrieve them again. This process enhances the speed of the project but configuring it is optional.

Database: The type of database you intend to connect to; currently, only Mysql is available.

Below is a sample of the configuration class:

After you have configured the config class, pass it to the main library class.

For example:

5. Main Project Folders

After a successful connection, these folders will be created in the directory set by you (in configuration class):

6. How to Create a Data Table

To do this, enter the Tables folder in your project folder (MyProject\Tables\). This folder contains files that are used to create a data table.

To do this, enter the project folder and create a php file in the Tables folder

[!NOTE] the file name and class name must match. Also, make sure to use the namespace that includes your project name and the term Tables (PROJECT-NAME\Tables). Finally, ensure that you inherit from the \Azad\Database\Table\Make class.

In the above example, we are creating a data table named Users in a file called Users.php

(PROJECT-NAME\Tables\Users.php).

Now it’s time to configure the data table. The table settings are done in the class constructor (__construct).

First, pay attention to the following example:

It is clear that the columns of the data table are added line by line. Using the Name method, we specify the name of the data table column, and with Type, we determine the type of data we intend to store in it. Finally, with Size, we set the size of the data. This is the simplest way to create columns for a data table. However, the data column settings are not limited to these three methods.

Methods

column_name : The column name is set in this method. The input to this method is a string and it needs to be called in the most initial state. Other methods that are explained later require the name defined by this method.

[!CAUTION] PHP Fatal error: Uncaught Azad\Database\Table\Exception: You need to specify the column name first.

class_type: This method determines the data type of the column. Below is a list of data types available.

[!NOTE] that the input parameter must be a class from \Azad\Database\Types\

Types:

[!CAUTION] If the set data type does not exist, you will encounter such an error. PHP Fatal error: Uncaught Azad\Database\Table\Exception: The 'type' value entered is not valid

size: Data Type Size

normalizer_name (string) : normalizer Name

What are Normalizers? Normalizers help you to standardize the appearance of your data. For example, they can make all letters lowercase (this aids in data evaluation and extraction)

In the Magic section, this feature has been elaborated upon in detail

encrypter_name (string) : Encrypter Name

What is an Encryptor? This feature encodes the data before storage and decrypts it upon retrieval. With this, you can easily encrypt a column and automatically access the decrypted data when displaying it.

This feature is explained in detail in the Magic section.

table_name (string) : Main table name

column_name (string) : Main column name

Properties

Also, you can use the following Properties.

This ensures that the set columns do not repeat in other rows.

for example:

Correlation of tables data

This capability creates a link between tables, allowing the user to find themselves in another table without the need for a repeated search

Manual mode:

Use of Tables Correlation:

How to set up correlation?

First, you need to specify the parent table with IndexCorrelation method. the data from this table will be stored in a global variable after receiving the data.

Now using the internal Correlation method to get the data from the second table and define it in a static function.

OriginColumn : Column name to be evaluated using (use PRIMARY column here)

table_name : Destination Table Name

column : The name of the column to which the OriginColumn data is sent

Correlation data output is an array of all found data.

[!IMPORTANT] You need to extract your data before using correlation, this rule is set to prevent heavy library processing

Result:

Second example :

Result:

[!WARNING] Risk of data mismatch in case of lack of attention

Result:

Second example (No problem) :

Result:

6. How do we import data into a data table?

After the data table configuration is complete, to start injecting data, select your desired data table using the Table method.

The output of this method is another class with methods like Select and Insert and functions that you have defined in the library class. Currently, we use the Insert method to inject data.

for example:

After selecting the table, insert your data into the table using the Insert method

Methods

column_name : Set the name of the table column in this field.

data : The data you want to consider for this column.

In summary, after selecting the data table, there are two methods for adding data: the Key method, which is for the name of the data column, and the Value method, which specifies the value of this column.

Finally, after determining the data, the data injection process begins with the End() command. If you need the ID identifier of your data, the output of End is actually the last id added to the data table.

How can I check if a row exists?

Sometimes it’s necessary to verify whether the data you intend to add to a database might encounter duplication issues. To achieve this, we use the RowExists method to check whether a row exists in our data table or not

In the example below, we examine whether the name Mohammad has been registered for the column first_name in the Users data table or not. The output of this method is true (meaning it exists) and false (meaning it does not exist).

After ensuring that this data has not been saved in our table, we add it to the table (this prevents errors related to unique and primary_key)."

Using enums

Before using enums, it’s necessary to talk about their application. What is an enum? These constants are typically used to make code more readable and maintainable by replacing numeric codes with descriptive names. Enums make your code more understandable by allowing you to use meaningful names instead of magic numbers. Enums provide compile-time type checking, preventing invalid values from being assigned to variables. Enums group related constants, which can be helpful when you have a set of related values that should be considered together.

To start using enums, you need to follow a few steps:

1. Creating a New Enum

Navigate to the enums folder within your project’s directory and create a file with the name of your enum. In this example, we are using UserStatus ().

Then, specify that this is a class for an enum by using

[!NOTE] This step is not mandatory but helps in making your code more readable).

Next, create an enum using the keyword. PHP Document

Consider the following example where we have set two states for the status of our users’ accounts, Active and Inactive:

You can also assign values to each of the expressions, but note that you must specify the data type. For instance, if you consider the number 1 for Active, you must set that this is an enum of type int:

[!NOTE] However, it is not mandatory to set a value for each case, as the library will automatically operate according to your enum.

2.Data Table Settings

Open the data table file of your choice. After setting the name, use the Enum method from the name method. Look at the example below:

After assigning the Enum, the process of saving and retrieving data will change.

To add a row and also to update it, you must definitely use the defined enum. In the example below, you will see a sample of adding data.

Now, when you want to retrieve the value of , the output of the will be the same as the defined enum.

Pay attention to the example below

You can also add functions to your enum. For example, we have added a function to translate the status into Persian.

Now, when we want to display the user’s status in Persian, we do it like this:

7. How do we extract a row or multiple rows from a data table?

Here, we will work with another method called Select. This method get the column whose data you need; if you want the data of all columns, use the asterisk (*).

After selecting your column, you can search for a specific row/rows with the WHERE, AND, OR.

Pay attention to the example below.

Methods

column_name : The name of the column you want to get your data with its value.

value : Column value.

column_name : The name of the column you want to get your data with its value.

value : Column value.

column_name : The name of the column you want to get your data with its value.

value : Column value.

After completing the data search with WHERE clauses, you can access the data using these three methods:

Data(): This includes all the retrieved data.

FirstRow(): Displays the first retrieved data.

LastRow(): Displays the last retrieved data.

The output of all three methods consists of three attributes:

Result: The retrieved data.

Update: Used for updating or editing data.

Condition: Contains conditional expression methods.

Currently, we intend to extract data, so we’ll use the Result attribute.

Rows

This method displays the list of all found data. for example:

Row

This method get the first/last data found.

8. How to Update a row

To update one or more columns, after selecting Row (via FirstRow | LastRow | Data) Use the Update properties.

[!IMPORTANT] if the output of $User is more than one value, All of them will be updated.

Example:

Now, to update the value of a column we have three methods:

Methods:

new_value : Set a new value in this parameter

number : The number you want to add to the previous value. (value + number = new_value)

number : The number you want to subtract to the previous value. (number - value = new_value)

Condition

You can also use conditional commands to update your data. Examples: (In this example, all columns of USD that range from 300 to 600 are added to 50 values.)

Methods

column_name : Column name

column_name : Column name

column_name : Column name

Conditional Methods

Functionals

Functional functions, (which are located in the main project) to expedite work. This part is still developing. (src\Functional)

Magic

Normalizers

In a simple sense, it means sorting data. Use Normalizer when you plan to store data regularly in the database.

tEhRAn -> Tehran

The data is sent to Normalizers before being saved, then the Normalizer stores it in the database after the changes are made.

normalizer

How to make new Normalizer

To do this, enter the project folder and create a php file in the Normalizers folder (AzadSql\Normalizers\x.php) In this example, we use the name "strtolower", using Normalizer "strtolower" to store the user's names as case lower (AzadSql\Normalizers\strtolower.php)

Rules:

  1. Similar to the table structure, the file name needs to be the same as the class name.
  2. Use the namespace. ProjectName\Normalizers
  3. Inherit from \Azad\Database\Magic\Normalizer
  4. Create a method called Normalization as static and set only one parameter for its input. Rebuild ($Data)
  5. The end. The output of Normalization is stored in the table and $Data is the data that is intended to be stored in the table

$Data -> strtolower::Normalization($Data) -> Save

And in the table you want to do for the column you want:

Encrypters

If you intend to store vital data, use this method!

Data encryption is done automatically and you don't need to decrypt and encrypt continuously.

Data is encrypted before it is stored and decrypted after it is received.

Encrypter

How to make new Encrypter:

To do this, enter the project folder and create a php file in the Encrypters folder (AzadSql\Encrypters\x.php) In this example, we use the name "Base64", Using Base64 Encrypter, encrypts your data to base64 before storing it and decrypts when receives it.

(x.php -> Base64.php)

Rules:

  1. Similar to the table structure, the file name needs to be the same as the class name.
  2. Use the namespace. ProjectName\Encrypters
  3. Inherit from \Azad\Database\Magic\Encrypter
  4. Create a method called Encrypt as static and set only one parameter for its input. Encrypt($Data)
  5. Create a method called Decrypt as static and set only one parameter for its input. Decrypt($Data)
  6. The end.

Example:

And in the table you want to do for the column you want:

Plugins

The plugin has access to all database data. It can receive data and change them. The processes are done inside the plug-in class. Plugins help you improve your teamwork and also publish plugins on the web Plugins help you process the data in another folder and access its defined methods in the main file.

How to make Plugin

To do this, enter the project folder and create a php file in the Plugins folder (MyProject\Plugins\x.php)

Rules:

  1. Similar to the table structure, the file name needs to be the same as the class name.
  2. Use the namespace. ProjectName\Plugins
  3. Inherit from \Azad\Database\Magic\Plugin

self::Table(X) : Select a table to work on data.

$this->Data : This value is set during coding, the data needed for the plugin is placed in this section

Example of making a plugin:

You can also import another plugin through the IncludePlugin method.

Example of loading a plugin:

Jobs

An interesting and very efficient feature. Have you ever experienced that after transferring funds between two users, one user’s balance decreases but the second user’s balance does not increase? It’s true, you might have been entangled in consecutive and complex conditions, but here we have a better solution.

Using this feature, all data are evaluated before execution, listed in order, and if the execution of one of them encounters a problem, the previous data is recovered, and no data is changed.

Jobs

Pay attention to the example below

In the above example, we intend to transfer 10,000 monetary units between two users.

The clean architecture of this feature is as follows:

First, define the users whose data you need.

Then, define the variables you require.

Now, start operations on the data.

Finally, check the data before starting the job.

In the first step, it is necessary to define a new job, which is done with the NewJob method.

After defining a Job to receive data from a table (in the example above, Users), use the following structure:

The input for the Find method is actually the value of the Primary Key column. The job automatically detects which column is the Primary Key and uses the value of this method to evaluate with the Primary column.

Then, using the From method, specify which table the data belongs to.

[!Note] that in the Job, do not manually change the data at all; we need the previous data and the new data, and this requires properly writing the jobs.

In the next step, to save the update command, we use the following structure:

In the Table method, enter the name of the table you intend to work with its rows. For the Select input, enter the name of the column you intend to edit the data of (in the example above, amount).

Now, define what the new input should be with the To method. Finally, using the Who method, specify which user you are editing (use the variables defined in the previous step by the Find method).

Now, finally, we can evaluate the data before starting the commands, and in case of a problem, use the Exception method.

[!Note] that the input for this method must definitely be the ExceptionJob class.

After the complete configuration of the Job, the commands are executed in the defined order using the Start command.

Library Developers Guide :fist_right: :fist_left:

How to make a new data types

Data types are created as object-oriented, this helps us to set specific features for each of the data types. The folder for data types is in /src/types.

Rules:

  1. The file name is equal to the class name.
  2. use the namespace Azad\Database\Types
  3. Inheriting from Init

Class components are divided into two sets of properties and methods.

Properties

$SqlType : A required properties that needs to be defined as public. The value of these properties is sent to sql as a data type. BIGInt example:

$Primary : A boolean value، if true is defined، this column is automatically treated as primary key ID example:

Methods

Adds a new value in SQL after the data type CreatedAt example:


After the user uses Insert for the first, this value is considered for the column.

After the user updates one of their columns, the column defined by this method changes to the output of this method.

Random example:


After the user intends to store a data, the data is sent to this method and its output is replaced as new data.

$value : The value that is being stored in the database

AutoLess example:


After the programmer intended to get his data from the table column, the table column data was first sent to this method and its output was set as output data.

$value : The value that is being stored in the database

ArrayData example:


All versions of database with dependencies

PHP Build Version
Package Version
Requires php Version >=8.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 azaddevx/database contains the following files

Loading the files please wait ....