Getting Started

Getting Started

Introduction

BS PHP-MySQL simplifies working with MySQL database using PHP. To get started, download BS PHP-MySQL from Here and add it to your project.

 

Integration

You can integrate your project with by including on requiring main_classes.php to your PHP project files as shown below.

<?php
     require_once("bs-php-mysql/main_classes.php");
?>

Inside bs-php-mysql library folder you will also find db_connect.php and db_connect_vars.php. db_connect.php contains a database connector. Inside db_connect.php replace $db_host,$db_name,$db_user and $db_password values with your MySQL server configuration.

<?php
     $db_host="localhost"; //put your database host here
     $db_name="bs_test"; //put your database name here
     $db_user="root"; //put your database user here
     $db_password=""; //put your password here

The configurations set in db_connect.php are primary configurations for your project. In cases where you will be using multiple databases in your projects you can set secondary database configurations in db_connect_vars.php file as shown below.

<?php
     $db_var_name=array($db_host,$db_user,$db_password,$db_name);

For example

<?php
     $shop_db=array("localhost","root","","bs_test");

You will also be required to include db_connect_vars.php in PHP files where you want to use secondary database. This will be discussed in more details later in other sections of this documentation.

 

Usage

To use library classes you will be required to first create an object of the particular class and then use that object to get a specific function in the class.This documentation will cover details on how to use every class in the library.

 

Simple usage example

This example show how you can retrieve data from a database table.For you to retrieve data from a database table you do like so:

//Creating object
$retrieveObj=new BS_RETRIEVE();

//bs_retriever($table_name,$fields_to_be_retrieved,$fetch_option)
$data=$retrieveObj->bs_retriever("table_name","*","fetchAll");

In this example, the data retrieved will be stored in $data variable.

It is this simple!!!

Through out this documentation we will be using the database name ‘bs_test’ and database table structure shown below.

CREATE TABLE `users` (
     `user_id` int(45) NOT NULL,
     `firstname` varchar(60) NOT NULL,
     `lastname` int(60) NOT NULL,
     `age` int(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Was this page helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *