MySQL Class for DB Managment PDO

A long time in my private projects i use class what im made for MySQL Managment scripts which are an integral Frameworks and I pulled the best,faster and high security resolve for managment MySQL DB.I use in all projects PDO and I wanted to share with you for easier job and help in development production for MySQL security

Than lets start

How to install ?

Class is group the most important of all PDO functions with that as the use of a lot simplified.First unpackage archive,all files and folders transfer in reproduction folder of your script than in the beginning of its turn one file - config.php in my example

<?php
  include_once "config.php";
?>

How to use class ?

Inquiry (MySQL Query)

<?php
  $SQL = "SELECT FROM Table";
  $DataBase->Query($SQL);
?>

These scripts start the transaction and database

Feedback (MySQL Result)

<?php
  $SQL = "SELECT FROM Table";
  $DataBase->Query($SQL);
  $DataBase->Execute();
  // $Result = $DataBase->Single(); - One result.
  // $Results = $DataBase->ResultSet(); - All results (string).
?>

Bind Data with Query (MySQL Bind)

<?php
  $ID = "1";
  $SQL = "SELECT FROM Table WHERE ID = :ID";
  $DataBase->Query($SQL);
  $DataBase->Bind(':ID', $ID); // Can use more times in string, for various parameters.
  $DataBase->Execute();
  // $Result = $DataBase->Single(); - One result.
  // $Results = $DataBase->ResultSet(); - All results (String).
?>

Counting results (MySQL Row Count)

<?php
  $SQL = "SELECT FROM Table";
  $DataBase->Query($SQL);
  $DataBase->Execute();
  $ResultsCount = $DataBase->RowCount(); - One result.
?>

Other functions

<?php
  $DataBase->LastID(); // Last ID.
  $DataBase->StartTransaction(); // Start transaction.
  $DataBase->EndTransaction(); // End transaction.
  $DataBase->CancelTransaction(); // Cancel transaction (Eliminate all entered during the same).
  $DataBase->DebugParams(); // Parameters for debug.
?>

I hope I have helped someone.

3 Likes

Thank you for this tutorial :grinning: it has been recategorized!

2 Likes

thank you heh :blush:

1 Like

Does using the PDO speed up connections to the database?

This should be the case here :slight_smile:

If used with prepared statements it increases security. For example:

<?php
$pdo = new PDO("mysql:host=localhost;dbname=database;","username","password");
$stmt = $pdo->prepare("UPDATE `users` SET email=:email");
$stmt->execute(array('email'=>'example@gmail.com'));
?>

This is a very safe way to update email, even when email is a parameter from a _GET request.

1 Like

But the connection speed is better? I need a Boolean answer, yes or no!

1 Like

Can’t give you a Boolean answer, it depends on the availability of the MySQL server at the time of the request.

3 Likes

Thanks, I’m still learning PHP and Mysql.

1 Like

thanks for staff responses i was working :smile:

2 Likes

thanks for this article it motivates me to start exploring MySQL databases. I want to make interactive opinion polls for my website but have a lot of learning to do first. :relieved:

2 Likes

Great tutorial! Thank you so much, that helps me a lot :slight_smile:

2 Likes