Code Monkey home page Code Monkey logo

easy-php's Introduction

easy-php

PHP Data Access Object Library. Making PHP easy and fast to use.

How to use

Download the library, extract and save it in your project folder.

Include the path to the easy-php.php file to the file you intend to use in your project.

<?php 
require "path to your connection file";
require "path to easy-php.php file";
...

Features

  1. Database connection.
  2. Delete data.
  3. Update data.
  4. Select data.
  5. Insert data.

Functions explained

Here is an explanation of functions in this library.

set_connection($connection) This is function is found in INSERT, DELETE, UPDATE AND SELECT actions. It accepts one parameter which is the connection. It is a requiremnt to carry out any actions to the database.

<?php
$delete->set_connection($conn);
$insert->set_connection($conn);
$update->set_connection($conn);
$select->set_connection($conn);

DELETE functions It has 4 functions.

  1. Set connection as explained above.
  2. set_deletestatement("delete sql statement") You pass your sql statement using this function.
  3. set_data(array("put the data here")); This function lets you pass the data to the prepared statement. Data is passed in array format.
  4. delete_data() This function executes the delete action and returns a failure of success message. -see code

INSERT functions It has 4 functions.

  1. Set connection as explained above.
  2. set_insertstatement("insert sql statement") You pass your sql statement using this function.
  3. set_data(array("put the data here")); This function lets you pass the data to the prepared statement. Data is passed in array format.
  4. insert_data() This function executes the insert action and returns a failure of success message.-see code

UPDATE functions It has 4 functions.

  1. Set connection as explained above.
  2. set_updatestatement("update sql statement") You pass your sql statement using this function.
  3. set_data(array("put the data here")); This function lets you pass the data to the prepared statement. Data is passed in array format.
  4. update_data() This function executes the insert action and returns a failure of success message.-see code

SELECT functions It has 4 functions.

  1. Set connection as explained above.
  2. set_selectstatement("select sql statement") You pass your sql statement using this function.
  3. set_data(array("put the data here")); This functions accepts two types of data types(An array with the data and the word false). If you pass false it means there are no conditions in the select statement. If you pass data in array format it means there are conditions in the select statement .
  4. select_data() This function executes the insert action and returns a failure of success message.-see code

1. Database connection

Inclucde the Dbconnection.php file.

Set the hostname, database name, username, password then call the get_connection() function and set it to a variable.

<?php 
require "path to Dbconnection.php";
$db=new Dbconnection();
$db->set_hostname("localhost");
$db->set_databasename("websample");
$db->set_username("root");
$db->set_password("");
$conn=$db->get_connection();

Delete data

Include the connection and the actions.php file. Then set the required functions. Use $delete->report to get the response after the execution.

<?php 
require "path to your connection file";
require "path to easy-php.php file";

$delete->set_connection($conn);//set the connection
$delete->set_deletestatement("DELETE FROM tbl_arrays WHERE id=?");//pass the sql statement
$delete->set_data(array("1"));//pass data
$delete->delete_data();//execute
echo $delete->report;//get the response

Insert data

Include the connection and the actions.php file. Then set the required functions. Use $insert->report to get the response after the execution.

<?php 
require "path to your connection file";
require "path to easy-php.php file";

$insert->set_connection($conn);
$insert->set_insertstatement("INSERT INTO tbl_arrays(name,age,location)VALUES(?,?,?)");
$insert->set_data(array("Victor","20","Kenya"));
$insert->insert_data();
echo $insert->report;

Update data

Include the connection and the actions.php file. Then set the required functions. Use $update->report to get the response after the execution.

<?php 
require "path to your connection file";
require "path to easy-php.php file";

$update->set_connection($conn);
$update->set_updatestatement("UPDATE tbl_arrays SET name=?,age=?,location=? WHERE id=?");
$update->set_data(array("Vic","30","Uganda","15"));
$update->update_data();
echo $update->report;

Select data

Include the connection and the actions.php file. Then set the required functions. Use $select->report to get the response after the execution.

<?php 
require "path to your connection file";
require "path to easy-php.php file";

$select->set_connection($conn);
$select->set_selectstatement("SELECT * FROM tbl_arrays WHERE id=?");
$select->set_data(array("3"));//pass data or use the next line of code
//$select->set_data("false");//use this if there are is no data being passed
$select->select_data();
while($data=$select->report->fetch_array()){
echo " id ".$data[0]." ";
echo " name ".$data[1];
}

easy-php's People

Contributors

ngangavic avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

millicentkinoti

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.