PHP Classes

Nemiro Data PHP: Compose and execute MySQL or PostgreSQL queries

Recommend this page to a friend!
  Info   View files Example   View files View files (1)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 180 All time: 8,687 This week: 75Up
Version License PHP version Categories
nemiro-data-php 2.0Custom (specified...5.3PHP 5, Databases
Description 

Author

This class can compose and execute MySQL or PostgreSQL queries.

It provides a common interface to access MySQL using MySQLi or PostgreSQL databases.

The common interface can execute queries with prepare statements or not, returning query results in arrays, etc..

Picture of Aleksey Nemiro
  Performance   Level  
Name: Aleksey Nemiro <contact>
Classes: 6 packages by
Country: Russian Federation Russian Federation
Age: 39
All time rank: 201858 in Russian Federation Russian Federation
Week rank: 179 Up10 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Example

<?php

# include config file
require_once 'config.php';

# include the db client classes file (use own path of the file location)
require_once '../Import.php';

# import MySql client
use Nemiro\Data\MySql as MySql;
# import command class
use Nemiro\Data\DBCommand as DBCommand;
# import parameters type list
use Nemiro\Data\DBParameterType as DBParameterType;

# best practice is to use 'try { } catch { }' blocks
try
{
   
# create client instance
   
$client = new MySql();

   
# you can specify the text of the query into the Command property
   
$client->Command = 'SELECT * FROM users';

   
# and execute the query by any method:
    # $client->GetRow(); # return single row
    # $client->GetTable(); # return all rows
    # $client->GetData(); # return array tables

    # for example, get all rows
   
$table = $client->GetTable();
   
var_dump($table);

   
# you can build a query from the input parameters,
    # but you will need to check the type and value of incoming data
    # it is bad practice
   
$client->Command = 'DELETE FROM users WHERE id_users = '.(int)$_GET['id'];

   
# it is best to use parameterized queries
   
$client->Command = new DBCommand('DELETE FROM users WHERE id_users = @id_users');
   
$client->Command->Parameters->Add('@id_users', $_GET['id'], DBParameterType::Integer);
   
# or
    # $client->Command->Parameters->Add('@id_users', $_GET['id']);
    # or
    # $client->Command->Parameters->Add('@id_users').SetValue($_GET['id']);
    # it is a safe solution

    # execute the query
   
$affectedRows = $client->ExecuteNonQuery();

    echo
'Deleted: '.$affectedRows.'<br />';
}
catch (
Exception $ex)
{
    echo
'Error: '.$ex->getMessage();
}
?>


  Files folder image Files  
File Role Description
Files folder imagesamples (1 file)

  Files folder image Files  /  samples  
File Role Description
  Accessible without login Plain text file mysql_simply.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:180
This week:0
All time:8,687
This week:75Up