承接 elvis-leite/recordset-database 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

elvis-leite/recordset-database

最新稳定版本:v1.2

Composer 安装命令:

composer require elvis-leite/recordset-database

包简介

A simple library for managing database connections and building queries in PHP.

README 文档

README

This is a simple library for managing database connections and building queries in PHP.

Composer link

Description

This library is designed to facilitate the interaction between PHP and databases using Mysqli. It provides methods for database connection, query execution, record selection, insert.

Improved PHP Code for Database Operations This code sample demonstrates how to use the RecordSetDatabase library to perform various database operations. Here's an overview of what each part of the code does:

  • Include the Library:
    You need to include the library's autoload file to access its functionality.

  • Import the RecordSetDatabase Class: Use the use statement to import the RecordSetDatabase class for easier access.

  • Database Credentials: Set up your database credentials (host, username, password, database name, and charset) in the provided variables.

  • Select Method: Use the select method to fetch data from a table based on conditions like a where clause, order by clause, and limit clause. Iterate over the data using the DataGenerator method and display the results.

  • Query Method: Execute custom SQL queries with the Execute method and retrieve results in a similar way.

  • Data Generator with DATE Formatting: Format date values with the formFld method and display the results.

  • INSERT Data: Insert a new record into the database and receive the inserted record's ID.

  • UPDATE Data: Update records in the database and get a boolean result indicating success or failure.

  • DELETE Data: Delete records from the database and get a boolean result indicating success or failure.

Requirements This library requires PHP 8.0 or greater to function correctly.

Make sure you meet this requirement before using the code.

Usage

Instalation

composer require elvis-leite/recordset-database

To use this library just follow the examples below:

Database

<?php

// Include the library's autoload file
require 'vendor/autoload.php';

// Import the RecordSetDatabase class
use RecordSetDatabase\RecordSetDatabase;

// Database Credentials
$DB_HOSTNAME = 'localhost';
$DB_USERNAME = 'database';
$DB_PASSWORD = 'root';
$DB_DATABASE = 'pass';
$DB_CHARSET = 'utf8';

// Creating a RecordSetDatabase instance
$rs = new RecordSetDatabase();

// Generating data with the Select method
$rs->Select('table_name', 'where_clause', 'order_clause', 'limit_clause');

while ($rs->DataGenerator()) {
    echo '<tr><td>' . $rs->fld('table_field') . '</td></tr>';
}

// Generating data with a Query
$rs = new RecordSetDatabase();
$sql = "select * from table_name";
$rs->Execute($sql);

while ($rs->DataGenerator()) {
    echo '<tr><td>' . $rs->fld('table_field') . '</td></tr>';
}

// Data Generator with DATE formatting
$rs = new RecordSetDatabase();
$rs->Select('table_name');

while ($rs->DataGenerator()) {
    echo '<tr><td>' . $rs->formatFld('table_field') . '</td></tr>';
}

// This would return: <tr><td>25/10/2022 às 13:01:21</td></tr>

// INSERT data
$rs = new RecordSetDatabase();
$data = [
        'id' => (string) $rs->setAutoCode('id', 'user'),
        'name' => 'Tatys',
        'mail' => 'tatiss@gmail.com',
        'pass' => 's$2y$10$zKdjHmKbmJ6GVOIrApOiTO5sOpZSZkbHiscY9Kab/CnsKF.2dVt3S'
    ];
$rs->Insert($data, 'user');

// UPDATE 
$rs = new RecordSetDatabase();
$result = $rs->Update(['name' => 'Elvis Leite'], 'table_name', 'id = 1');

// DELETE 
$rs = new RecordSetDatabase();
$rs->Delete('user', 'id = 4');

// Get Field
$rs = new RecordSet();
echo $rs->getField('id', 'user', 'id = 1');

?>

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2022-11-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固