|
||
---|---|---|
.. | ||
examples | ||
src | ||
tests | ||
.gitattributes | ||
.gitignore | ||
.scrutinizer.yml | ||
composer.json | ||
composer.lock | ||
LICENSE | ||
phpunit.xml | ||
README.md |
This is a library that I have been building to act similar to the WPDB class used for database interactions on Wordpress. I have expanded that library and added things like extended insert, replace, and update syntax building.
Setup
-
After loading open "src/DBConfig.php"
-
Update top 4 defined constants with your system configuration (default server, user, password, and schema)
-
After including autoload, you can create an object as follows
$db = new Godsgood33\Php_Db\Database();
OR
$conn = new mysqli("server", "user", "pwd", "schema");
$db = new Godsgood33\Php_Db\Database($conn);
Using the second allows you to connect to ANY server that is not the default (however, if the connection DROPs out for any reason, it will be restored with the default server info)
We recommend using this class to extend your existing database connection class. Because instantiating will automatically call the parent class constructor and connect to the database using the default values. Then within your DB class you build the function calls that will perform the queries that you need.
class MyDB extends Godsgood33\Php_Db\Database
{
public function getUsers()
{
$this->select("users");
return $this->execute();
}
}
$db = new MyDB();
Options
-
$autorun static variable - if set to true script will auto-commit query after building it and return the result (using example above)
public function getUsers() { return $this->select("users"); }
Query Type List
- select
- builds select query
- selectCount
- builds select count(1) query
- insert
- builds insert query for one (1) row
- extendedInsert
- builds insert query with more than one row
- update
- builds update query for one row
- extendedUpdate
- builds update query for more than one row (requires table to pull from and to update)
- replace
- builds replace into query for one row
- extendedReplace
- builds replace query for more than one row
- delete
- builds delete query (allows for joins and targeted deletion)
- drop
- builds drop query (allows for dropping multiple tables)
- truncate
- builds truncate query
- createTable
- builds create table query (allows for temporary, DDL syntax only, or create from select statement)
- createTableJson
- builds a DDL create table query from json (examples/create_table_json.json)
- alterTable
- builds alter table query (allows for add, modify, and drop column syntax)
- fieldExists
- queryies table to check for presents of a specific field
- fieldData
- queryies table to get field data
- fieldCheck
- not implemented
- tableExists
- checks for presence of a table
- fields
- helper method to build field list
- where
- helper method to build where clause list
- flags
- helper method to parse option flag array
- groups
- helper method to build group by syntax
- having
- helper method to build having syntax
- order
- helper method to build order by syntax
- fetchAll
- helper method to return all rows from a query
- isConstraint
- helper method to check for presence of a constraint