flostone/mysql

此包已 弃用 且不再维护。未建议替代包。
此包的最新版本(1.3.0)没有可用的许可信息。

纯PHP和其他应用的MySQL库

1.3.0 2017-10-27 12:57 UTC

README

#任何PHP项目的MySQL助手 ##安装 require flostone/mysql-plainphp
##使用 Include the class using
use FloStone\MySQL\MySQL;
使用以下方式连接到数据库
$sql = MySQL::connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
现在可以使用查询函数执行查询
$results = $sql->query("SELECT * FROM projects");
结果将立即返回,但您也可以使用以下方式获取结果
$results = $sql->results(); ##使用语句 如果您想使其更简单,您还可以使用多个语句作为函数。
例如,如果您想创建一个WHERE子句,您也可以编写
$projects = $sql->select('*')->where('id', '=', 1)->get();
为了使用这些语句,您首先必须指定一个表
$sql->table('projects');
直到最终更改,表名将保持不变。
您还可以使用多个语句链式调用表
$projects = $sql->table('projects')->select('*')->where('name', 'like', '%Test%')->orWhere('title', '=', 'Testingproject')->get();
通常它的工作方式与Laravel Eloquent Builder类似,它基于Laravel Eloquent Builder。
###可用的语句 public function insert(array $columns, array $values);
public function create($table, $closure)
public function update($id, array $columns, array $values);
public function drop($table);
public function table($table);
public function select($select = '*');
public function where($column, $operator, $value = NULL);
public function orWhere($column, $operator, $value = NULL);
public function whereIn($column, array $values);
public function join($table, $primary, $operator, $other = NULL);
public function leftJoin($table, $primary, $operator, $other = NULL);
public function rightJoin($table, $primary, $operator, $other = NULL);
public function outerJoin($table, $primary, $operator, $other = NULL);
public function fullOuterJoin($table, $primary, $operator, $other = NULL);
public function orderBy($column, $order = 'desc');
public function all();
public function raw($sql);
public function columnExists($column);
在某些情况下,运算符也可以是值,在这种情况下,默认将运算符设置为'='。
###创建函数闭包 当您想使用“create”函数时,您需要将闭包或匿名函数作为第二个参数传入。
此函数接受一个参数
function($table){}
表参数是一个“Blueprint”实例,用于定义表中的一些字段。
创建查询的基本示例可能如下所示
$sql->create('projects', function(Blueprint $table){ $table->increments(); $table->string('name'); $table->timestamps(); });
####Blueprint函数 public function increments($name = 'id');
public function string($name, $null = false, $length = 255);
public function integer($name, $null = false, $unsigned = false);
public function text($name, $null = false);
public function custom($customquery);
public function timestamps();
自定义查询必须作为单个列定义实现
tinyint(1) DEFAULT 0 NOT NULL