A simple PHP library for MySQL DB access and querying
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
deebee.php

README.md

DeeBee

What is it?

A simple PHP library for MySQL DB access and querying. I created this for a class project. I personally, can never remeber how to connect to MySQL database in PHP. So I have a template file lying on my remote and local server. But I figured instead of just copying that code each time, I'd create a class and then just use that to access the database. I think it turned out well, but I'll let you be the judge of that.

Installation

  cd /path/to/put_deebee_in
  git clone git@github.com:ekdevdes/deebee.git "deebee"

Usage

Setting the Database Credentials (Two Ways)

  require_once("deebee/deebee.php");

First Way

Note: All the options in the array are optional (including the "database" option) as there are two different ways of establishing a connection

  $db = new DeeBee([
    "username" => "root",
    "pw" => "root",
    "hostname" => "localhost",
    "database" => "github_db" 
  ]);

OR

Second Way

Note: The database name is optional

  $db = new DeeBee();
  $db->username = "root";
  $db->pw = "root";
  $db->hostname = "localhost";
  $db->database = "github_db";

Establishing a Connection and Selecting a Database

Note: the database name parameter of the set_db() function is optional, and if not specified will use the database name passed in during class instantiation (whether you've done it the first or second way (above))

$db->connect->set_db("github_db");

OR

$db->connect();
$db->set_db("github_db");

Last but not least, querying

For the shorter queries....

Note: The query() function returns an array of the results

  $results = $db->query("SELECT * FROM users");

For the longer queries, I'm talking 10+ lines you can use a SQL file....

Note: The first parameter is the path to SQL file (or any file containing SQL really) that you want to use and the second parameter tells DeeBee to use a SQL file for the query string instead of the query string being passed in a parameter

  $results = $db->query("./github.sql", TRUE);

OK, that's everything...enjoy!