DB interface for MySQL

1.0.1 2019-09-23 07:04 UTC

This package is auto-updated.

Last update: 2024-10-24 18:43:35 UTC


README

convenient library to work with mysql for php

Install for composer

composer require reptily/db

Initialization module

require "./vendor/autoload.php";

$config = [
        "host" => "localhost",
        "login" => "root",
        "pwd" => "*******",
        "db" => "php_db_test"
        ];

$DB = new \openWeb\DB($config);

Create table

$table = [
                "id" =>[
                        "type"=>"int",
                        "count"=>11,
                        "isNull"=>false,
                        "autoIncrement"=>true
                ],
                "name"=>[]
        ];
$DB->Create("account",$table);

Insert value

$DB->account->Insert(["name"=>"user"]);

Select all rows and output to array

$row=$DB->account->Select()->getArray();
print_r($row);

Select all rows and output to json string

echo $DB->account->Select()->getJson();

Select table account only id colum

echo $DB->account->where(["id" => 1])->Select()->getJson();

Select table account only id colum

echo $DB->account->field(["id"])->Select()->getJson();

Select table account and where id = 1 and id = 3

echo $DB->account->where('or',["id" => 1],["id" => 3])->Select()->getJson();

Select table account only id colum and where id = 1

echo $DB->account->field(["name"])->where(["id" => 1])->Select()->getJson();

Select table account id and name colum and where id = 1

echo $DB->account->field(["id","name"])->where(["id" => 1])->Select()->getJson();

Select table account where id more 1

echo $DB->account->where("id > 1")->Select()->getJson();

Inner table blog

echo $DB->account->inner("blog")->on("id","id")->Select()->getJson();

Left table blog

echo $DB->account->left("blog")->on("id","id")->Select()->getJson();

Update values in table blog

$DB->blog->set(['name' => 'update'])->where(["id" => 2])->Update();

Delete values in table account

$DB->account->where(["id" => 1])->Delete()