MySQL 数据库接口

1.0.1 2019-09-23 07:04 UTC

This package is auto-updated.

Last update: 2024-09-24 18:34:58 UTC


README

方便的用于与MySQL交互的PHP库

为composer安装

composer require reptily/db

初始化模块

require "./vendor/autoload.php";

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

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

创建表

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

插入值

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

选择所有行并将结果输出到数组

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

选择所有行并将结果输出为JSON字符串

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

选择表account的仅id列

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

选择表account的仅id列

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

选择表account且id = 1且id = 3

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

选择表account的仅id列且id = 1

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

选择表account的id和name列且id = 1

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

选择表account的id大于1的行

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

内部表blog

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

左连接表blog

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

在表blog中更新值

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

在表account中删除值

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