Skip to content

vinsbg/DBConnection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

DBConnection

Simple class for database connection

Instructions

# Place your database credentials
private static $dbName = '';
private static $dbHost = '';
private static $dbUsername = '';
private static $dbUserPassword = '';

Usage

include 'dbConnection.inc.php';

// establish connection 
$pdo = Database::connect(); 

    // selecting from database with prepared statements
    $value = $pdo->prepare('SELECT * FROM table WHERE id= ?);
    
    // binding parameter
    $value->bindParam(1, $id, PDO::PARAM_INT); 
    
    // executing
    $value->execute();
    
    // fetching results
    $result = $value->fetch();

    if( $result > 0) {
        // working with results
    }
    else {
        // working without results
    }
    
// closing connection to database    
Database::disconnect(); 

About

Simple class for database connection

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages