koyabu/webapi

dev-main 2024-09-29 01:27 UTC

This package is auto-updated.

Last update: 2024-09-29 01:27:54 UTC


README

安装

composer require koyabu/webapi

composer.json

如果你的 composer.json 中出现关于 minimum-stability 的错误,请编辑该文件并添加或编辑此参数

    "minimum-stability": "dev",
    "prefer-stable": false

config.php

配置示例,您可以查看文件:vendor/koyabu/webapi/config.sample.php

namespace Koyabu\Webapi;
require_once 'vendor/autoload.php';

$config = [];
$config = [];
$config['APPS_NAME'] = 'KOYABU PHP FRAMEWORK';
$config['HOME_DIR'] = __DIR__ . DIRECTORY_SEPARATOR;

$config['mysql'] = array(
    'host' => 'localhost',
    'user' => 'root',
    'pass' => '',
    'data' => 'test'
);
$API = new Koyabu($config);
?>

Dropbox 保存,不要忘记在 $config['dropbox'] 中设置您的 Dropbox 秘钥和令牌,参见 config.sample.php 示例

$API = new Koyabu($config);
$filename = 'test.txt';
var_dump($API->save_dbx($filename));

MySQL/MariaDB 查询

// INSERT
$params = array(
    'id' => $id,
    'name' => $name
);
$primary_index = 'id';
$API->save($params,$table_name,'INSERT',$primary_index);
$API->save($params,$table_name,'REPLACE',$primary_index);
$API->save($params,$table_name,'UPDATE',$primary_index);

Params = 列名 => 值名。您的数组索引以数据库表列名命名。$primary_index 默认 = id

// DELETE
$params = array(
    'db_colname' => $value
)
$API->delete($params,$table_name);

使用与表列名相同的 $params 索引名称,查询将删除 db_colname = $value 的数据

// Get Single Record
$value_id = 2;
$table_name = 'member';
$colname = 'id';

$result = $API->get($value_id,$table_name,$colname);
var_dump($result);

// Get single record with multiple filter
$value_id = 2;
$table_name = 'member';
$colname = array('gender' => 'male', 'category' => 'student', 'city' => 'Manado');

$result = $API->get($value_id,$table_name,$colname);
var_dump($result);
// Select with query
$qry = $API->select("select * from test");
while($result = $API->fetch()) {
    print_r($result);
}

$qry = $API->select("select * from test");
while($result = $API->fetch('row')) {
    print_r($result);
}