diff --git a/README.md b/README.md index f4b76c5..afd3580 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a simple abstraction library for MySQL DML operations. For example: ```php -MySQL->for(string $table) +MySQL->from(string $table) ->where(?array ...$conditions) ->order(?array $order_by) ->limit(int|array|null $limit) @@ -60,24 +60,24 @@ $db = new MySQL($host, $user, $pass, $db); All executor methods [`select()`](#select), [`update()`](#update), and [`insert()`](#insert) will return a [`mysqli_result`](https://www.php.net/manual/en/class.mysqli-result.php) object or boolean. -# FOR +# FROM ```php -MySQL->for( +MySQL->from( string $table ): self; ``` -All queries start by chaining the `for(string $table)` method. This will define which database table the current query should be executed on. +All queries start by chaining the `from(string $table)` method. This will define which database table the current query should be executed on. *Example:* ```php -MySQL->for("beverages")->select("beverage_type"); +MySQL->from("beverages")->select("beverage_type"); ``` # SELECT -Chain `MySQL->select()` anywhere after a [`MySQL->for()`](#for) to retrieve columns from a database table. +Chain `MySQL->select()` anywhere after a [`MySQL->from()`](#from) to retrieve columns from a database table. Pass an associative array of strings, CSV string, or null to this method to filter columns. @@ -91,7 +91,7 @@ In most cases you probably want to select with a constraint. Chain the [`where() ### Example ```php -$beverages = MySQL->for("beverages")->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages +$beverages = MySQL->from("beverages")->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages ``` ``` [ @@ -109,7 +109,7 @@ $beverages = MySQL->for("beverages")->select(["beverage_name", "beverage_size"]) # INSERT -Chain `MySQL->insert()` anywhere after a [`MySQL->for()`](#for) to append a new row to a database table. +Chain `MySQL->insert()` anywhere after a [`MySQL->from()`](#from) to append a new row to a database table. Passing a sequential array to `insert()` will assume that you wish to insert data for all defined columns in the table. Pass an associative array of `[column_name => value]` to INSERT data for specific columns (assuming the other columns have a [DEFAULT](https://dev.mysql.com/doc/refman/8.0/en/data-type-defaults.html) value defined). @@ -124,7 +124,7 @@ MySQL->insert( #### Example ```php -MySQL->for("beverages")->insert([ +MySQL->from("beverages")->insert([ null, "coffee", "latte", @@ -138,7 +138,7 @@ true # DELETE -Chain `MySQL->delete()` anywhere after a [`MySQL->for()`](#for) to remove a row or rows from the a database table. +Chain `MySQL->delete()` anywhere after a [`MySQL->from()`](#from) to remove a row or rows from the a database table. ```php MySQL->delete( @@ -152,7 +152,7 @@ This method takes at least one [`MySQL->where()`](#where)-syntaxed argument to d #### Example ```php -MySQL->for("beverages")->insert([ +MySQL->from("beverages")->insert([ null, "coffee", "latte", @@ -166,7 +166,7 @@ true # UPDATE -Chain `MySQL->update()` anywhere after a [`MySQL->for()`](#for) to modify existing rows in a database table. +Chain `MySQL->update()` anywhere after a [`MySQL->from()`](#from) to modify existing rows in a database table. ```php MySQL->update( @@ -178,7 +178,7 @@ MySQL->update( ### Example ```php -MySQL->for("beverages")->update(["beverage_size" => 10]); // UPDATE beverages SET beverage_size = 10 +MySQL->from("beverages")->update(["beverage_size" => 10]); // UPDATE beverages SET beverage_size = 10 ``` ```php true @@ -201,7 +201,7 @@ MySQL->where( ### Example ```php -$coffee = MySQL->for("beverages")->where(["beverage_type" => "coffee"])->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages WHERE (beverage_type = "coffee"); +$coffee = MySQL->from("beverages")->where(["beverage_type" => "coffee"])->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages WHERE (beverage_type = "coffee"); ``` ```php [ @@ -284,7 +284,7 @@ MySQL->order( ``` ```php -$coffee = MySQL->for("beverages")->order(["beverage_name" => "ASC"])->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages ORDER BY beverage_name ASC +$coffee = MySQL->from("beverages")->order(["beverage_name" => "ASC"])->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages ORDER BY beverage_name ASC ``` ```php [ @@ -315,7 +315,7 @@ MySQL->limit( This will simply `LIMIT` the results returned to the integer passed ```php -$coffee = MySQL->for("beverages")->limit(1)->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages WHERE beverage_type = "coffee" LIMIT 1 +$coffee = MySQL->from("beverages")->limit(1)->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages WHERE beverage_type = "coffee" LIMIT 1 ``` ```php [ @@ -330,7 +330,7 @@ $coffee = MySQL->for("beverages")->limit(1)->select(["beverage_name", "beverage_ This will `OFFSET` and `LIMIT` the results returned. The first argument will be the `LIMIT` and the second argument will be its `OFFSET`. ```php -$coffee = MySQL->for("beverages")->limit(3, 2)->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages LIMIT 3 OFFSET 2 +$coffee = MySQL->from("beverages")->limit(3, 2)->select(["beverage_name", "beverage_size"]); // SELECT beverage_name, beverage_size FROM beverages LIMIT 3 OFFSET 2 ``` ```php [ diff --git a/src/MySQL.php b/src/MySQL.php index 48f9cef..5d7c2e6 100644 --- a/src/MySQL.php +++ b/src/MySQL.php @@ -66,7 +66,7 @@ */ // Use the following table name - public function for(string $table): self { + public function from(string $table): self { // Reset all definers when a new query begins $this->where(); $this->limit(); @@ -76,6 +76,14 @@ return $this; } + #[\Deprecated( + message: "use MySQL->from() instead", + since: "2.1.5", + )] + public function for(string $table): self { + $this->from($table); + } + // Create a WHERE statement from filters public function where(?array ...$conditions): self { // Unset filters if null was passed