Code Monkey home page Code Monkey logo

php-library's Introduction

PHP-Library

Some useful php libraries for easing code :)

Working with DB (PDO)

Instantiating Object and setting table

$db = new DB();
$db->table('tablename');

Or Do it Directly (DID)

// Fetching results
DB::table('tablename')->get(); // will fetch every result from table

For Complex Querying

$query = DB::table('tablename')->query("SELECT col, FROM @table . . .");

// @table refer to current table reference, if set with table() method.

Fetching results

/**
 * obj | array stash($type = '{}' || '[]')
 * obj | array record($type = '{}' || '[]')
 *
 * $type parameter can be '{}' fetching results as object or '[]' for arrays
 * $type parameter by default set to '{}'
 */

$db = new DB();
$query = $db->table('tablename')->get();

// single result
$result = $query->stash();

// for heap of results
$result = $query->record();

Fetching data for single columns

DB::table('tablename')->get('column')

Fetching multiple columns of your choice

DB::table('tablename')->get([
  'cols' => ['col1', 'col2', 'col3', 'col4']
])

Making use of table reference for every query

$db = new DB();
$db->table('tablename') // set table

// tablename will be set automatically as table reference for every query you made
$query1 = $db->get(); // no need to set table again
$result = $query1->stash();

$query2 = $db->where('col1', 'value')->get('col1'); // same for here
$result = $query2->stash();

Working with Assets

To link css and js file:

Assets::bootstrap([
   'filename1' => [
     'css' => [
	"path/to/style.css" ...
      ],
      'js' => [
	 "path/to/script.js" ...
      ]
    ],
   'filename2' => [
     'css' => [],
      'js' => []
    ]
]);

To link same style or script file to multiple files:

Assets::bootstrap([
   'filename1 | filename2' => [
     'css' => [
	"path/to/style.css" ...
      ],
      'js' => [
	 "path/to/script.js" ...
      ]
    ]
]);

// You can add as much filenames as you want

If you're not using routing simple edit the bool isfile(string $file) method according to your need.

php-library's People

Contributors

hamzaavvan avatar johnforte avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

johnforte

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.