定制 rcastera/mysql-wrapper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

rcastera/mysql-wrapper

Composer 安装命令:

composer require rcastera/mysql-wrapper

包简介

MySQL Abstraction Class

关键字:

README 文档

README

This is a class that I've used in some of my projects for years. It's a simple wrapper to MySQL written in PHP5 that allows you to connect, run queries and get results. It's been used in production sites for some time now and I've re-factored it several times.

Setup

Add a composer.json file to your project:

{
  "require": {
      "rcastera/mysql-wrapper": "v1.0.0"
  }
}

Then provided you have composer installed, you can run the following command:

$ composer.phar install

That will fetch the library and its dependencies inside your vendor folder. Then you can add the following to your .php files in order to use the library (if you don't already have one).

require 'vendor/autoload.php';

Then you need to use the relevant class, and instantiate the class. For example:

Getting Started

require 'vendor/autoload.php';

use rcastera\Database\Mysql\Mysql;

$db = new Mysql('localhost', 'DATABASE', 'USERNAME', 'PASSWORD');

Examples

Select all records from contacts table.
<?php
    require 'vendor/autoload.php';
    use rcastera\Database\Mysql\Mysql;
    $db = new Mysql('localhost', 'DATABASE', 'USERNAME', 'PASSWORD');
?>
<?php $contacts = $db->executeQuery('SELECT * FROM contacts')->asObject(); ?>
<?php if ($contacts): ?>
<ul>
    <?php foreach($contacts as $contact): ?>
    <li><?php echo $contact->first_name; ?> <?php echo $contact->last_name; ?></li>
    <?php endforeach; ?>
</ul>
<?php else: ?>
<p>No contacts found.</p>
<?php endif; ?>
<?php unset($db); ?>
Insert a record into the contacts table.
<?php
    require 'vendor/autoload.php';
    use rcastera\Database\Mysql\Mysql;
    $db = new Mysql('localhost', 'DATABASE', 'USERNAME', 'PASSWORD');
?>
<?php $inserted = $db->executeQuery('INSERT INTO contacts (first_name, last_name, email) VALUES ("Isabella", "Castera", "email@domain.com")')->wasInserted(); ?>
    <?php if ($inserted): ?>
    <p>Contact Isabella inserted with id, <?php echo $inserted; ?></p>
    <?php else: ?>
    <p>No contacts found.</p>
    <?php endif; ?>
<?php unset($db); ?>
Delete a record from the contacts table.
<?php
    require 'vendor/autoload.php';
    use rcastera\Database\Mysql\Mysql;
    $db = new Mysql('localhost', 'DATABASE', 'USERNAME', 'PASSWORD');
?>
<?php $deleted = $db->executeQuery('DELETE FROM contacts WHERE first_name = "Isabella"')->wasDeleted(); ?>
    <?php if ($deleted): ?>
    <p>Contact Isabella deleted.</p>
    <?php else: ?>
    <p>No contacts found.</p>
    <?php endif; ?>
<?php unset($db); ?>
Update a record in the contacts table.
<?php
    require 'vendor/autoload.php';
    use rcastera\Database\Mysql\Mysql;
    $db = new Mysql('localhost', 'DATABASE', 'USERNAME', 'PASSWORD');
?>
<?php $updated = $db->executeQuery('UPDATE contacts SET last_name = "Branson" WHERE first_name = "Richard"')->wasUpdated(); ?>
    <?php if ($updated): ?>
    <p>Contact Richard updated.</p>
    <?php else: ?>
    <p>No contacts found.</p>
    <?php endif; ?>
<?php unset($db); ?>

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b my_branch)
  3. Commit your changes (git commit -am "Added something")
  4. Push to the branch (git push origin my_branch)
  5. Create an Issue with a link to your branch
  6. Enjoy a refreshing Coke and wait

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-09-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固