tazzy / helpers

常用助手函数

dev-master 2018-12-31 11:15 UTC

This package is not auto-updated.

Last update: 2024-09-24 18:09:41 UTC


README

php 助手函数,用于数据库、文件处理、验证、电子邮件、哈希、令牌和会话等常见任务

使用 Tazzy-Helpers

  • 在您的项目中使用 Tazzy-Helpers

    • include "Tazzy-Helpers/autoload.php";
  • 数据库访问

  • 创建 secrets.php 文件

  • 添加配置

$GLOBALS['config'] = [
  'db'        => [
      'driver'   => 'mysql',
      'host'     => 'localhost',
      'username' => 'root',
      'password' => 'secret',
      'db'       => 'database',
      'prefix'   => ''
  ]
];
* edit the config file to set your database config settings. Note Database uses PDO
  • 使用数据库助手函数有两种方式:一种是通过 querybuilder 类使用 PHP 代码创建 SQL 查询,另一种是继承 Table 类在您的模型上使用它以实现基本的 ORM

数据库使用

  • 原始查询
  $users = DB::getInstance()->query('Select * from users');
  if(!$users->count()){
      echo 'no such user found';
  }else{
    foreach($users->result() as $user){
        echo $user->username;
    }
  }
  • 插入到数据库
$insert = DB::getInstance()-> insert('users',array(
  'firstname'=> 'john',
  'lastname'=> 'doe',
));
  • 更新
$update = DB::getInstance()->update('users',array('id','=', '1'),array(
   'firstname'=> 'alex'
 ));