flostone/mysql

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (1.3.0) of this package.

MySQL Library for plain php and other applications

1.3.0 2017-10-27 12:57 UTC

README

#MySQL helper for any PHP Project ##Installation require flostone/mysql-plainphp
##Usage Include the class using
use FloStone\MySQL\MySQL;
Connect to the database using
$sql = MySQL::connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
Now execute queries with the query function
$results = $sql->query("SELECT * FROM projects");
The results will always be returned immediately however you can also get the results using
$results = $sql->results(); ##Using Statements If you want to make it a little easier you can also use several statements as functions.
E.g. if you wanted to make a where clause you could also write
$projects = $sql->select('*')->where('id', '=', 1)->get();
In order to use these statements you first have to specify a table:
$sql->table('projects');
The table name will stay the same for every query until you eventually change it.
You can also chain the table with several statements:
$projects = $sql->table('projects')->select('*')->where('name', 'like', '%Test%')->orWhere('title', '=', 'Testingproject')->get();
Generally it works as the Laravel Eloquent Builder, which it is based on.
###Available Statements 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);
In some cases the operator may also be the value, in that case the operator will be set to '=' by default.
###Create function closure When you want to use the "create" function, you need to pass in a closure or anonymous function as second argument.
This function takes one parameter:
function($table){}
The table parameter is a "Blueprint" instance, which is used to define certain fields in you table.
A basic example of a create query could look like this:
$sql->create('projects', function(Blueprint $table){ $table->increments(); $table->string('name'); $table->timestamps(); });
####Blueprint functions 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();
A custom query must be implemented as one column definition:
tinyint(1) DEFAULT 0 NOT NULL