Download the PHP package octa-php/octa-pdo without Composer
On this page you can find all versions of the php package octa-php/octa-pdo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download octa-php/octa-pdo
More information about octa-php/octa-pdo
Files in octa-php/octa-pdo
Package octa-pdo
Short Description A light-weight PHP-PDO database class, this database class is inspired by codeigniter's active record.
License MIT
Informations about the package octa-pdo
OctaPDO
A light-weight PHP-PDO database class, this database class is inspired by codeigniter's active record.
Author
Getting Started
installing OctaPDO via composer.
Prerequisites
How To Use
OctaPDO needs a paramater consisting your database connection. so we'll just assume that you already have a database connection similar below.
To call the OctaPDO, simply pass your database connection on the OctaPDO class like the below example
OctaPDO Active Record Documentation
$db->get();
Runs the selection query and returns the result. Can be used by itself to retrieve all records from a table
The second and third parameters enable you to set a limit and offset clause:
You'll notice that the above function is assigned to a variable named $query, which can be used to show the results:
$db->select();
Permits you to write the SELECT portion of your query:
$db->select() accepts an optional second parameter. If you set it to FALSE, OctaPDO will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.
$db->join();
Permits you to write the JOIN portion of your query:
Multiple function calls can be made if you need several joins in one query.
If you need a specific type of JOIN you can specify it via the third parameter of the function. Options are: left, right, outer, inner, left outer, and right outer.
$db->where();
This function enables you to set WHERE clauses using one of four methods:
-
Simple key/value method:
Notice that the equal sign is added for you. If you use multiple function calls they will be chained together with AND between them: -
Custom key/value method:
You can include an operator in the first parameter in order to control the comparison: -
Associative array method:
You can include your own operators using this method as well: - Custom string:
You can write your own clauses manually:
$db->where()
accepts an optional third parameter. If you set it to FALSE, OctaPDO will not try to protect your field or table names with backticks.
$db->or_where();
This function is identical to the one above, except that multiple instances are joined by OR:
$db->where_in();
Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate
$db->or_where_in();
Generates a WHERE field IN ('item', 'item') SQL query joined with OR if appropriate
$db->where_not_in();
Generates a WHERE field NOT IN ('item', 'item') SQL query joined with AND if appropriate
$db->or_where_not_in();
Generates a WHERE field NOT IN ('item', 'item') SQL query joined with OR if appropriate
$db->like();
This function enables you to generate LIKE clauses, useful for doing searches.
- Simple key/value method:
If you use multiple function calls they will be chained together with AND between them:
If you want to control where the wildcard (%) is placed, you can use an optional third argument. Your options are 'before', 'after' and 'both' (which is the default).
If you do not want to use the wildcard (%) you can pass to the optional third argument the option 'none'.
- Associative array method:
$db->or_like();
This function is identical to the one above, except that multiple instances are joined by OR:
$db->not_like();
This function is identical to like(), except that it generates NOT LIKE statements:
$db->or_not_like();
This function is identical to not_like(), except that multiple instances are joined by OR:
$db->group_by();
Permits you to write the GROUP BY portion of your query:
You can also pass an array of multiple values as well:
$db->order_by();
Lets you set an ORDER BY clause. The first parameter contains the name of the column you would like to order by. The second parameter lets you set the direction of the result. Options are asc or desc, or random.
You can also pass your own string in the first parameter:
Or multiple function calls can be made if you need multiple fields.
$db->insert();
Generates an insert string based on the data you supply, and runs the query. You can either pass an array or an object to the function. Here is an example using an array:
The first parameter will contain the table name, the second is an associative array of values. Here is an example using an object:
The first parameter will contain the table name, the second is an object.
$db->update();
Generates an update string and runs the query based on the data you supply. You can pass an array or an object to the function. Here is an example using an array:
Or you can supply an object:
You'll notice the use of the $db->where() function, enabling you to set the WHERE clause. You can optionally pass this information directly into the update function as a string:
Or as an array:
You may also use the $db->set() function described above when performing updates.
$db->delete();
Generates a delete SQL string and runs the query.
The first parameter is the table name, the second is the where clause. You can also use the where() or or_where() functions instead of passing the data to the second parameter of the function:
An array of table names can be passed into delete() if you would like to delete data from more than 1 table.
If you want to delete all data from a table, you can use the truncate() function, or empty_table().
Example Of Queries Using OctaPDO Active Record
LIST OF PRE-DEFINED CLASS
License
- MIT
- Copyright 2019 © OctaPDO.
Acknowledgments
- Twig Template Engine of Symfony
- Phpti (https://arshaw.com/phpti/)
Support
Reach me out on this social media site.
Linkedin.com