Skip to content

Simply execute prepared and unprepared queries with MySQL and PHP.

License

Notifications You must be signed in to change notification settings

neil-yoga-crypto/php-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

The only PDO MySQL class you need. Configured to support prepared and unprepared queries and to return the id of a newly created row if necessary. Creates the database if not exists.

Installation

  1. Extract PHP files in your www directory.
  2. Install MySQL database server if not installed

Usage

Configure your database

require('db.php');
Db::config('yourDatabasename','yourUsername','yourPassword');
Db::getDb();

Select a table

$sql = "SELECT * FROM yourTablename"; 
$results = Db::getDb()->query($sql);
foreach($results as $result)
{
    echo $result['yourColumnName'];
}

Select a table with prepared statements

$sql = "SELECT * FROM yourTablename WHERE id = :id";
$userInputValue = 'yourUnescapedValue';
$preparedStatements = array(':id'=>$userInputValue);
$results = Db::getDb()->query($sql,$preparedStatements);
foreach($results as $result)
{
    echo $result['yourColumnName'];
}

Insert a table with prepared statements

$sql = "INSERT INTO yourTablename(id,name) VALUES(:id,:name)";
$userInputId = 'yourUnescapedValue';
$userInputName = 'yourUnescapedValue';
$preparedStatements = array(':id'=>$userInputId,':name'=>$userInputName);
Db::getDb()->query($sql,$preparedStatements);

Insert a table with prepared statements and get the id

$sql = "INSERT INTO yourTablename(name) VALUES(:name)";
$userInputName = 'yourUnescapedValue';
$preparedStatements = array(':name'=>$userInputName);
$id = Db::getDb()->queryAndReturnId($sql,$preparedStatements);

License

Licensed under The MIT License (MIT).

About

Simply execute prepared and unprepared queries with MySQL and PHP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages