diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c87de2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +composer.lock +composer.phar +/vendor diff --git a/.travis.yml b/.travis.yml index 5d3df84..352638a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,12 @@ language: php + php: - - 5.2 - 5.3 - - 5.4 \ No newline at end of file + - 5.4 + - 5.5 + +before_script: + - curl -s http://getcomposer.org/installer | php + - php composer.phar install --prefer-source --no-interaction --dev + +script: phpunit \ No newline at end of file diff --git a/MIT-LICENSE.txt b/LICENSE similarity index 100% rename from MIT-LICENSE.txt rename to LICENSE diff --git a/README-pt.md b/README-pt.md index da435e6..31e7b51 100644 --- a/README-pt.md +++ b/README-pt.md @@ -1,4 +1,4 @@ -*[Read the documentation in English](https://github.com/giovanniramos/PDO4YOU/blob/master/README.md)* +*[Read the documentation in English](https://github.com/giovanniramos/PDO4You/blob/master/README.md)* --- @@ -32,64 +32,31 @@ O padrão de projeto Singleton foi adotado para otimizar a conexão, garantindo -Carregando o arquivo de inicialização +Introdução -------------------------------------------------- +O bootstrap é o arquivo responsável por carregar o autoloader e todas as dependências do projeto. +Se não estiver disponível, será exibida uma mensagem de confirmação para iniciar a instalação com Composer. + ~~~ php ~~~ -`PDO4You.class.php`: contém a implementação do objeto PDO de conexão. +`PDO4You.php`: classe que contém a implementação do objeto PDO de conexão. `PDO4You.config.php`: arquivo de configuração inicial, de acesso ao servidor e base de dados. -`PDO4You.library.php`: arquivo contendo um autoloading de classes, e funções internas da classe. - `PDO4You.settings.ini`: contém as definições para cada adaptador de conexão com uma base de dados. +`Describe.php`: Describe é uma classe usada para listar todos os campos em uma tabela e o formato de dados de cada campo. +`Pagination.php`: Pagination é uma classe que permite listar os registros de forma paginada, semelhante ao Google. -Drivers suportados pelo servidor --------------------------------------------------- - -Execute o método abaixo para verificar se o servidor tem suporte a um driver PDO específico de sua base de dados. -Os drivers suportados serão exibidos na tela. - -~~~ php - -~~~ - -Para habilitar algum driver não instalado, localize o arquivo php.ini, abra e procure por "extension=" sem as aspas, depois descomente as linhas a seguir conforme sua base de dados de preferência, removendo no início de cada linha o "ponto-e-vírgula" e após mudanças, reinicie o servidor. - -~~~ html -;extension=php_pdo.dll ; Esta DLL não será necessária a partir do PHP 5.3 -extension=php_pdo_mysql.dll ; MySQL 3.x/4.x/5.x / MariaDB -extension=php_pdo_pgsql.dll ; PostgreSQL -;extension=php_pdo_cubrid.dll ; CUBRID -;extension=php_pdo_oci.dll ; Oracle Call Interface -;extension=php_pdo_sqlsrv.dll ; Microsoft SQL Server / SQL Azure -;extension=php_pdo_dblib.dll ; Microsoft SQL Server / Sybase / FreeTDS -;extension=php_pdo_mssql.dll ; Microsoft SQL Server "Versão antiga" -;extension=php_pdo_sqlite.dll ; SQLite 2/3 - -~~~ - -Drivers PDO para o servidor Xampp:
-CUBRID (PHP 5.4): http://bit.ly/PDO_CUBRID-PHP54
-CUBRID (PHP 5.3): http://bit.ly/PDO_CUBRID-PHP53
-MS SQL Server 3.0 (PHP 5.4): http://bit.ly/PDO_SQLSRV-PHP54
-MS SQL Server 2.0 (PHP 5.2/5.3): http://bit.ly/PDO_SQLSRV-PHP53
-MS SQL Server (Versão antiga): http://bit.ly/PDO_MSSQL-PHP53 Estabelecendo uma conexão com a base de dados @@ -100,6 +67,14 @@ Para abstrair nossos mecanismos de acesso aos dados, usamos um DSN (Data Source ~~~ php +~~~ + +Para habilitar algum driver não instalado, localize o arquivo php.ini, abra e procure por "extension=" sem as aspas, depois descomente as linhas a seguir conforme sua base de dados de preferência, removendo no início de cada linha o "ponto-e-vírgula" e após mudanças, reinicie o servidor. + +~~~ html +;extension=php_pdo.dll ; Esta DLL não será necessária a partir do PHP 5.3 +extension=php_pdo_mysql.dll ; MySQL 3.x/4.x/5.x / MariaDB +extension=php_pdo_pgsql.dll ; PostgreSQL +;extension=php_pdo_cubrid.dll ; CUBRID +;extension=php_pdo_oci.dll ; Oracle Call Interface +;extension=php_pdo_sqlsrv.dll ; Microsoft SQL Server / SQL Azure +;extension=php_pdo_dblib.dll ; Microsoft SQL Server / Sybase / FreeTDS +;extension=php_pdo_mssql.dll ; Microsoft SQL Server "Versão antiga" +;extension=php_pdo_sqlite.dll ; SQLite 2/3 + +~~~ + +Drivers PDO para o servidor Xampp:
+CUBRID (PHP 5.4): http://bit.ly/PDO_CUBRID-PHP54
+CUBRID (PHP 5.3): http://bit.ly/PDO_CUBRID-PHP53
+MS SQL Server 3.0 (PHP 5.4): http://bit.ly/PDO_SQLSRV-PHP54
+MS SQL Server 2.0 (PHP 5.2/5.3): http://bit.ly/PDO_SQLSRV-PHP53
+MS SQL Server (Versão antiga): http://bit.ly/PDO_MSSQL-PHP53 + + + +Dependências -------------------------------------------------- -PHP 5.3 ou superior +PHP >= 5.3.2 @@ -343,13 +365,13 @@ Colaboradores -------------------------------------------------- Giovanni Ramos - -
-Veja também a lista de [colaboradores](http://github.com/giovanniramos/PDO4YOU/contributors) que participaram deste projeto. +Veja também a lista de [colaboradores](http://github.com/giovanniramos/PDO4You/contributors) que participaram deste projeto. Licença -------------------------------------------------- -Copyright (c) 2013 [Giovanni Ramos](http://github.com/giovanniramos) +Copyright (c) 2010-2013 [Giovanni Ramos](http://github.com/giovanniramos) -PDO4You é um software open-source licenciado sob a [MIT License](http://www.opensource.org/licenses/MIT) (MIT-LICENSE.txt) \ No newline at end of file +PDO4You é um software open-source licenciado sob a [MIT License](http://www.opensource.org/licenses/MIT) \ No newline at end of file diff --git a/README.md b/README.md index 4d2ca53..ce1e6f8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -*[Leia a documentação em Português](https://github.com/giovanniramos/PDO4YOU/blob/master/README-pt.md)* +*[Leia a documentação em Português](https://github.com/giovanniramos/PDO4You/blob/master/README-pt.md)* --- @@ -32,64 +32,31 @@ The Singleton design pattern was adopted to optimize the connection, ensuring a -Loading the bootstrap file +Getting Started -------------------------------------------------- +The bootstrap file is responsible for loading the autoloader and all project dependencies. +If not available, you will receive a confirmation message to start installation with Composer. + ~~~ php ~~~ -`PDO4You.class.php`: contains the implementation of the PDO object connection. +`PDO4You.php`: class that contains the implementation of the PDO object connection. `PDO4You.config.php`: initial configuration file, server access and database. -`PDO4You.library.php`: file containing an autoloading class, and internal functions of the class. - `PDO4You.settings.ini`: contains the settings for each adapter of connection to the database. +`Describe.php`: Describe is a class used to list all the fields in a table and the data format of each field. +`Pagination.php`: Pagination is a class that allows you to list the records so as paged, similar to Google. -Drivers supported by the server --------------------------------------------------- - -Execute the method below to check if the server supports a PDO driver specific to your database. -Supported drivers will be displayed on the screen. - -~~~ php - -~~~ - -To enable any driver not installed, locate the php.ini file, open it and look for "extension=" without quotes, then uncomment the following lines according to your database preferably, removing the beginning of each line the "semicolon" and after changes, restart the server. - -~~~ html -;extension=php_pdo.dll ; This DLL is not required as of PHP 5.3 -extension=php_pdo_mysql.dll ; MySQL 3.x/4.x/5.x / MariaDB -extension=php_pdo_pgsql.dll ; PostgreSQL -;extension=php_pdo_cubrid.dll ; CUBRID -;extension=php_pdo_oci.dll ; Oracle Call Interface -;extension=php_pdo_sqlsrv.dll ; Microsoft SQL Server / SQL Azure -;extension=php_pdo_dblib.dll ; Microsoft SQL Server / Sybase / FreeTDS -;extension=php_pdo_mssql.dll ; Microsoft SQL Server "Old version" -;extension=php_pdo_sqlite.dll ; SQLite 2/3 - -~~~ - -PDO drivers for the server Xampp:
-CUBRID (PHP 5.4): http://bit.ly/PDO_CUBRID-PHP54
-CUBRID (PHP 5.3): http://bit.ly/PDO_CUBRID-PHP53
-MS SQL Server 3.0 (PHP 5.4): http://bit.ly/PDO_SQLSRV-PHP54
-MS SQL Server 2.0 (PHP 5.2/5.3): http://bit.ly/PDO_SQLSRV-PHP53
-MS SQL Server (Old version): http://bit.ly/PDO_MSSQL-PHP53 Establishing a connection to the database @@ -100,6 +67,14 @@ To abstract our data access mechanisms, we use a DSN (Data Source Name = Data So ~~~ php +~~~ + +To enable any driver not installed, locate the php.ini file, open it and look for "extension=" without quotes, then uncomment the following lines according to your database preferably, removing the beginning of each line the "semicolon" and after changes, restart the server. + +~~~ html +;extension=php_pdo.dll ; This DLL is not required as of PHP 5.3 +extension=php_pdo_mysql.dll ; MySQL 3.x/4.x/5.x / MariaDB +extension=php_pdo_pgsql.dll ; PostgreSQL +;extension=php_pdo_cubrid.dll ; CUBRID +;extension=php_pdo_oci.dll ; Oracle Call Interface +;extension=php_pdo_sqlsrv.dll ; Microsoft SQL Server / SQL Azure +;extension=php_pdo_dblib.dll ; Microsoft SQL Server / Sybase / FreeTDS +;extension=php_pdo_mssql.dll ; Microsoft SQL Server "Old version" +;extension=php_pdo_sqlite.dll ; SQLite 2/3 + +~~~ + +PDO drivers for the server Xampp:
+CUBRID (PHP 5.4): http://bit.ly/PDO_CUBRID-PHP54
+CUBRID (PHP 5.3): http://bit.ly/PDO_CUBRID-PHP53
+MS SQL Server 3.0 (PHP 5.4): http://bit.ly/PDO_SQLSRV-PHP54
+MS SQL Server 2.0 (PHP 5.2/5.3): http://bit.ly/PDO_SQLSRV-PHP53
+MS SQL Server (Old version): http://bit.ly/PDO_MSSQL-PHP53 + + + +Dependencies -------------------------------------------------- -PHP 5.3 or higher +PHP >= 5.3.2 @@ -343,13 +365,13 @@ Collaborators -------------------------------------------------- Giovanni Ramos - -
-See also the list of [colaboradores](http://github.com/giovanniramos/PDO4YOU/contributors) who participated in this project. +See also the list of [colaboradores](http://github.com/giovanniramos/PDO4You/contributors) who participated in this project. License -------------------------------------------------- -Copyright (c) 2013 [Giovanni Ramos](http://github.com/giovanniramos) +Copyright (c) 2010-2013 [Giovanni Ramos](http://github.com/giovanniramos) -PDO4You is open-sourced software licensed under the [MIT License](http://www.opensource.org/licenses/MIT) (MIT-LICENSE.txt) \ No newline at end of file +PDO4You is open-sourced software licensed under the [MIT License](http://www.opensource.org/licenses/MIT) \ No newline at end of file diff --git a/bootstrap.php b/bootstrap.php index 40cb589..33fbd20 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,5 +1,23 @@ AUTOLOADER NOT FOUND'; + echo '

To continue the installation, click INSTALL and wait, or run install.sh from the command line.

'; + exit; + } else { + $output = shell_exec(INSTALL); + exit("
{$output}
"); + } + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 03f41da..8a01f41 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,27 @@ { "name": "giovanniramos/pdo4you", + "type": "library", "description": "Access SQL databases using the PDO extension", "keywords": ["database", "singleton", "pdo", "mysql", "postgresql", "sqlite", "mariadb", "oracle"], - "homepage": "https://github.com/giovanniramos/PDO4YOU", - "type": "library", + "homepage": "https://github.com/giovanniramos/PDO4You", "license": "MIT", "authors": [ { "name": "Giovanni Ramos", "email": "giovannilauro@gmail.com", + "homepage": "http://twitter.com/giovanni_ramos", "role": "Developer" } ], + "support": { + "issues": "https://github.com/giovanniramos/PDO4You/issues" + }, "require": { "php": ">=5.3.0" }, "autoload": { "psr-0": { - "PDO4YOU": "src" + "PDO4You": "src" } } } \ No newline at end of file diff --git a/demos/DemoCRUD.class.php b/demos/DemoCRUD.php similarity index 86% rename from demos/DemoCRUD.class.php rename to demos/DemoCRUD.php index 4b1dd7b..2b3250c 100644 --- a/demos/DemoCRUD.class.php +++ b/demos/DemoCRUD.php @@ -1,26 +1,17 @@ sql(); + $sql = self::sql(); // Execute the SQL query in a "pre-defined instance" and store the result $result = PDO4You::select($sql, $instance); - echo '
Demo with the method PDO4You::select()
'; + echo '
Demo with the method - PDO4You::select()
'; echo '
PDO4You::select(' . $this->getQuery($sql) . '); ' . $this->getResult($result) . '
'; } @@ -70,7 +61,7 @@ public function select($instance = null) public function allSelects() { // SQL query - $sql = $this->sql(); + $sql = self::sql(); // Execute the SQL query in a instance and store the result $result_1 = PDO4You::select($sql); @@ -78,16 +69,16 @@ public function allSelects() $result_3 = PDO4You::selectObj($sql); $result_4 = PDO4You::selectAll($sql); - echo '
Demo with the method PDO4You::select()
'; + echo '
Demo with the method - PDO4You::select()
'; echo '
PDO4You::select(' . $this->getQuery($sql) . '); ' . $this->getResult($result_1) . '
'; - echo '
Demo with the method PDO4You::selectNum()
'; + echo '
Demo with the method - PDO4You::selectNum()
'; echo '
PDO4You::selectNum(' . $this->getQuery($sql) . '); ' . $this->getResult($result_2) . '
'; - echo '
Demo with the method PDO4You::selectObj()
'; + echo '
Demo with the method - PDO4You::selectObj()
'; echo '
PDO4You::selectObj(' . $this->getQuery($sql) . '); ' . $this->getResult($result_3) . '
'; - echo '
Demo with the method PDO4You::selectAll()
'; + echo '
Demo with the method - PDO4You::selectAll()
'; echo '
PDO4You::selectAll(' . $this->getQuery($sql) . '); ' . $this->getResult($result_4) . '
'; } @@ -113,7 +104,7 @@ public function multipleInsert() // Store the result $result = PDO4You::execute($json); - echo '
Demo with the method PDO4You::execute() using the INSERT command
'; + echo '
Demo with the method - PDO4You::execute() using the INSERT command
'; echo '
PDO4You::execute(' . $this->getQuery($json) . '); ' . $this->getResult($result, true) . '
'; } @@ -149,7 +140,7 @@ public function multipleUpdate() // Store the result $result = PDO4You::execute($json); - echo '
Demo with the method PDO4You::execute() using the UPDATE command
'; + echo '
Demo with the method - PDO4You::execute() using the UPDATE command
'; echo '
PDO4You::execute(' . $this->getQuery($json) . '); ' . $this->getResult($result) . '
'; } @@ -181,7 +172,7 @@ public function multipleDelete() // Store the result $result = PDO4You::execute($json); - echo '
Demo with the method PDO4You::execute() using the DELETE command
'; + echo '
Demo with the method - PDO4You::execute() using the DELETE command
'; echo '
PDO4You::execute(' . $this->getQuery($json) . '); ' . $this->getResult($result) . '
'; } diff --git a/demos/DemoRegister.class.php b/demos/DemoRegister.php similarity index 80% rename from demos/DemoRegister.class.php rename to demos/DemoRegister.php index 4d98aaa..e8ff5fa 100644 --- a/demos/DemoRegister.class.php +++ b/demos/DemoRegister.php @@ -1,10 +1,12 @@ ERROR: ' . $error . '
'; + self::$message = 'ERROR: ' . $error . '

'; } else { // SQL insertion in JSON format $json = ' @@ -54,9 +53,10 @@ public function init() '; // Performs the new record and store the result - $result = PDO4You::execute($json); + list($total) = PDO4You::execute($json); - self::$message = 'Register #' . $result[0] . ' added successfully!!
'; + // Displays a success message + self::$message = 'Register #' . $total . ' added successfully!!

'; } } @@ -70,7 +70,9 @@ public function init() * */ public function getMessage() { - return self::$message; + $message = self::$message; + + return $message; } /** @@ -80,19 +82,20 @@ public function getMessage() public function getTotalRecords() { // Returns the total number of records in paging - if (PDO4You_pagination::$paging == true) { - return PDO4You_pagination::getTotalPagingRecords(); + if (Pagination::getPaging() == true) { + return Pagination::getTotalPagingRecords(); } else { return count(self::$hasRecords); } } /** - * Displays all records + * Displays the records * * */ - public function getRecords() + public function showRecords() { + // Displays the records if there if (self::$hasRecords) { $html = null; @@ -106,4 +109,4 @@ public function getRecords() } } -} +} \ No newline at end of file diff --git a/demos/demo1.php b/demos/demo1.php index 27559a7..c66418e 100644 --- a/demos/demo1.php +++ b/demos/demo1.php @@ -1,15 +1,12 @@ DEMOS › ALL SELECTS'; +echo '

DEMOS › SELECTS

'; // Creating an instance -$instance = new DemoCRUD; - -// Starting the main method -$instance->init(); +$demo = new DemoCRUD; // Displaying records between different instances of base -$instance->allSelects(); \ No newline at end of file +$demo->allSelects(); \ No newline at end of file diff --git a/demos/demo2.php b/demos/demo2.php index 44fb1a6..704775d 100644 --- a/demos/demo2.php +++ b/demos/demo2.php @@ -1,21 +1,18 @@ DEMOS › INSERT/UPDATE/DELETE'; // Creating an instance -$instance = new DemoCRUD; - -// Starting the main method -$instance->init(); +$demo = new DemoCRUD; // Example with inserting multiple records -$instance->multipleInsert(); +$demo->multipleInsert(); // Example to update multiple records -$instance->multipleUpdate(); +$demo->multipleUpdate(); // Example with multiple exclusion of records -$instance->multipleDelete(); \ No newline at end of file +$demo->multipleDelete(); \ No newline at end of file diff --git a/demos/demo3.php b/demos/demo3.php index 3182036..0690176 100644 --- a/demos/demo3.php +++ b/demos/demo3.php @@ -1,31 +1,31 @@ DEMOS › MULTIPLE INSTANCES'; -// Creating an instance -$instance = new DemoCRUD; +// Importing classes +use PDO4You\PDO4You; -// Starting the main method -$instance->init(); +// Creating an instance +$demo = new DemoCRUD; // Displaying records of the default instance "standard" -$instance->select(); +$demo->select(); -PDO4You::getInstance('bookstore', 'sqlite:../data/database_bookstore.db'); -PDO4You::getInstance('pdo4you', 'sqlite:../data/database_pdo4you.db'); +PDO4You::getInstance('bookstore', 'sqlite:data/database_bookstore.db'); +PDO4You::getInstance('pdo4you', 'sqlite:data/database_pdo4you.db'); // Displaying records from the data instance: bookstore -$instance->select('bookstore'); +$demo->select('bookstore'); // Displaying records from the data instance: pdo4you -$instance->select('pdo4you'); +$demo->select('pdo4you'); // Sets another instance PDO4You::setInstance('standard'); #PDO4You::setInstance('bookstore'); // Displaying records from the last data instance set -$instance->select(); \ No newline at end of file +$demo->select(); \ No newline at end of file diff --git a/demos/demo4.php b/demos/demo4.php index 48cb120..00a14e4 100644 --- a/demos/demo4.php +++ b/demos/demo4.php @@ -1,32 +1,15 @@ DEMOS › READ RECORDS'; +// Example with text from HTML Editor +echo '

DEMOS › HTML EDITOR

'; // Creating an instance -$instance = new DemoRegister; +$demo = new DemoCRUD; -// Starting the main method -$instance->init(); -?> +// Sample text +$sample_text = '

Lorem ipsum "dolor" sit amet

'; -
-
-

- -
:
-
:
-
:
-
-
- - getMessage(); ?> - -
- - : getTotalRecords(); ?> - - getRecords(); ?> -
\ No newline at end of file +// UPDATE books SET description = ? WHERE id = 1 +$demo->updateWhere($sample_text, 1); \ No newline at end of file diff --git a/demos/demo5.php b/demos/demo5.php index d35f77a..8d7cf92 100644 --- a/demos/demo5.php +++ b/demos/demo5.php @@ -1,18 +1,27 @@ DEMOS › HTML EDITOR'; +// Example with Read Records +echo '

DEMOS › READING RECORDS

'; // Creating an instance -$instance = new DemoCRUD; +$demo = new DemoRegister; +?> -// Starting the main method -$instance->init(); +
+
+

-// Sample text -$sample_text = '

Lorem ipsum "dolor" sit amet

'; +
:
+
:
+
:
+
+
-// UPDATE books SET description = ? WHERE id = 1 -$instance->updateWhere($sample_text, 1); \ No newline at end of file + getMessage(); ?> + + : getTotalRecords(); ?> + + showRecords(); ?> +
\ No newline at end of file diff --git a/demos/demo6.php b/demos/demo6.php index 58f3f37..3898105 100644 --- a/demos/demo6.php +++ b/demos/demo6.php @@ -1,43 +1,41 @@ DEMOS › PAGINATION'; +echo '

DEMOS › READING WITH PAGING

'; + +// Importing classes +use PDO4You\Pagination as pager; // Enable pagination -PDO4You::setPagination(); +pager::setPagination(); // Sets the page link -PDO4You::setLink('?p=demo6.php&n='); +pager::setPageLink('?p=demos/demo6.php&n='); // Sets the current page navigation -PDO4You::setPage(isset($_GET['n']) ? (int) $_GET['n'] : 1); +pager::setPage(isset($_GET['n']) ? (int) $_GET['n'] : 1); // Creating an instance -$instance = new DemoRegister; - -// Starting the main method -$instance->init(); +$demo = new DemoRegister; ?>
-

+

-
:
-
:
-
:
+
:
+
:
+
:
- getMessage(); ?> - -
+ getMessage(); ?> - : getTotalRecords(); ?> + : getTotalRecords(); ?> - getRecords(); ?> + showRecords(); ?> - +
\ No newline at end of file diff --git a/demos/index.php b/index.php similarity index 58% rename from demos/index.php rename to index.php index 739aa2c..8fd8b03 100644 --- a/demos/index.php +++ b/index.php @@ -1,18 +1,16 @@ @@ -20,7 +18,9 @@ PDO4You