Git Product home page Git Product logo

dbmng2's Introduction

DBMNG2.

Library Usage

#create a db connection
$db = DB::createDb($dsn, $user,$password );

#create an app object containing db and other parameters
$app=new App($db);

#define the form structure
$aForm=array(  
	'table_name' => 'test' ,
		'primary_key'=> array('id'),
		'fields'     => array(
				'id' => array('label'   => 'ID', 'type' => 'int', 'key' => 1 ) ,
				'name' => array('label'   => 'Name', 'type' => 'varchar')
		),
);
#define a param array
$aParam=array();

#create a Dbmng object
$dbmng=new Dbmng($app, $aForm, $aParam);

#return the data
$ret = $dbmng->select();

Installation and Test

First install composer

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

Clone the repository from github

$ git clone https://github.com/diegoguidotti/dbmng2.git
$ cd dbmng2

Install the dbmng2 dependencies using composer

$ composer update

Edit the file Router.php (vendor/respect/rest/library/Respect/Rest/Router.php) replacing the function sortRoutesByComplexity with the following one to allow a correct sort using PHP 7:

    protected function sortRoutesByComplexity()
    {
        usort(
            $this->routes,
            function ($a, $b) {
                $elementsa = preg_split('#/#', $a->pattern, 0, PREG_SPLIT_NO_EMPTY);
                $elementsb = preg_split('#/#', $b->pattern, 0, PREG_SPLIT_NO_EMPTY);
                if(end($elementsa) == '**' && end($elementsb) == '**')
                   return count($elementsa) < count($elementsb);
                if(end($elementsa) == '**')
                   return 1;
                if(end($elementsb) == '**')
                   return -1;
                if(count($elementsa) < count($elementsb)){
                   return -1;
                }
                if(count($elementsa) > count($elementsb)){
                   return 1;
                }
                $keysa = array_keys($elementsa, '*');
                $keysb = array_keys($elementsb, '*');
                if(count($keysa) < count($keysb)){
                   return -1;
                }
                if(count($keysa) > count($keysb)){
                   return 1;
                }
                for($index=0; $index < count($keysa); $index++){
                   if($keysa[$index] == $keysb[$index])
                       continue;
                   return $keysa[$index]<$keysb[$index];
                }
                return $a->method>$b->method;
                /*
		// Previous code - do not work correct with PHP 7
                $a = $a->pattern;
                $b = $b->pattern;
                $pi = AbstractRoute::PARAM_IDENTIFIER;

                //Compare similarity and ocurrences of "/"
                if (Router::compareRoutePatterns($a, $b, '/')) {
                    return 1;

                //Compare similarity and ocurrences of /*
                } elseif (Router::compareRoutePatterns($a, $b, $pi)) {
                    return -1;

                //Hard fallback for consistency
                } else {
                    return 1;
                }
                */
           }
        );
    }

Create a mySQL database and populate it using the file sql/dbmng2.sql and sql/test.sql (change root if you want to install using a different user) You can skip test.sql if you wan't run test unit

$ mysql -u root -p -e "create database dbmng2"
$ mysql -u root -p dbmng2 < sql/dbmng2.sql
$ mysql -u root -p dbmng2 < sql/test.sql

Update the configuration file

$ cp phpunit.xml.dist phpunit.xml
$ edit the phpunit.xml entering db_name, user and password
$ cp settings.default.php  settings.php
$ edit the settings.php entering db_name, user and password

For the JS library you need to install grunt (nodejs required) and then with npm install load the nodel packages

$ apt-get install libfontconfig1 fontconfig libfontconfig1-dev libfreetype6-dev #dipendenze per phantomJS per il test
$ apt-get install nodejs-legacy
$ sudo npm install -g grunt-cli
$ cd dbmng2/js/
$ npm install
$ grunt #run the grunt manager on the project

To test the api you should link the folder in the apache folder

$ ln -s ../dbmng2 /var/www/

Verify that the follow link respond

$ link: http://localhost/dbmng2/api/test_base
$ {"0":{"id":"1","name":"Diego","sex":""},"1":{"id":"2","name":"Michele","sex":""},"test_get":1}

Apache needs some modules (for rest and file upload)

$ sudo a2enmod rewrite
$ sudo a2enmod headers
$ sudo service apache2 restart

Verify that the directive AllowOverride is present in the root of the web server:

$ <Directory "/var/www/html">
$	AllowOverride All
$ </Directory>

Running the test

$ bin/phpunit

License

DBMNG2 is released under the MIT License. See the bundled LICENSE file for details.

dbmng2's People

Contributors

mamminim avatar diegoguidotti avatar klean97 avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

dbmng2's Issues

Add hidden widget

The hide widget can be used to store value not visible in the data entry form

Table alias

Gestire alias come nome tabella e come libreria

readonly html view

In form when a field is readonly add an hidden field plus a html decoded data

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.