project-open-data / db-to-api

Turns a Database into a Secure, RESTful API
448 stars 150 forks source link

"Must select a database" #14

Open wvmikep opened 10 years ago

wvmikep commented 10 years ago

I set up the config.php as instructed and I'm getting "Must select a database." Is there nothing else I need to edit?

layer67tech commented 10 years ago

Yes. You will need to edit the class.db-api.php file in the include folder. This is the manual process. /* * Register a new dataset * @param string $name the dataset name * @param array $args the dataset properties / function register_db( $name = null, $args = array() ) {

    $defaults = array(
        'name' => null,
        'username' => 'root',
        'password' => 'root',
        'server' => 'localhost',
        'port' => 3306,
        'type' => 'mysql',
        'table_blacklist' => array(),
        'column_blacklist' => array(),
        'ttl' => $this->ttl,
    );

    $args = shortcode_atts( $defaults, $args );
    $name = $this->slugify( $name );

    $this->dbs[$name] = (object) $args;

}
wvmikep commented 10 years ago

It doesn't help at all. Same result. I know the info I give it is good because I have a separate test page that returns data.

Trying to reverse engineer this, starting with shortcode_atts.

layer67tech commented 10 years ago

When you received the error message "Select a database", this means your config.php and class.db-api.php files have not been configured correctly. what do you have in the config.php and class.db-api files?

wvmikep commented 10 years ago

They're below.

With that said, it's failing in parse_query because there's no query string. If I put db and table in the query string (not intended per the instructions ... and doing so makes no sense anyway), I then get invalid database.

Doesn't make sense given how my little test page returns data from the db with the same credentials.

$args = array( 'name' => 'dbname', 'username' => 'dbuser', 'password' => 'dbpw', 'server' => 'localhost', 'port' => 3306, 'type' => 'mysql', 'table_blacklist' => array(), 'column_blacklist' => array(), );

register_db_api( 'berkeleywv-fe-inspections', $args );

function register_db( $name = null, $args = array() ) {

    $defaults = array(
        'name' => 'dbname',
        'username' => 'dbuser',
        'password' => 'dbpw',
        'server' => 'localhost',
        'port' => 3306,
        'type' => 'mysql',
        'table_blacklist' => array(),
        'column_blacklist' => array(),
        'ttl' => $this->ttl,
    );

    $args = shortcode_atts( $defaults, $args );
    $name = $this->slugify( $name );

    $this->dbs[$name] = (object) $args;

}
layer67tech commented 10 years ago

This appears to be a database and server access issue. Test your sample db_user , db_pass, db_host and db_name in a separate SQL Admin tool to see if you can access the database server.

wvmikep commented 10 years ago

That "test page" is separate from db-to-API. Phpmyadmin has no issues either.

Sent from my iPhone

On Mar 1, 2014, at 10:00 PM, "Patrick K. Johnson Jr." notifications@github.com wrote:

This appears to be a database and server access issue. Test your sample db_user , db_pass, db_host and db_name in a separate SQL Admin tool to see if you can access the database server.

— Reply to this email directly or view it on GitHub.

layer67tech commented 10 years ago

okay, try accessing one of your tables in the database. e.g.: http://localhost/berkeleywv-fe-inspections/table.json e.g.: http://localhost/berkeleywv-fe-inspections/table.xml e.g.: http://localhost/berkeleywv-fe-inspections/table.html

wvmikep commented 10 years ago

Must select a database

Sent from my iPhone

On Mar 1, 2014, at 10:42 PM, "Patrick K. Johnson Jr." notifications@github.com wrote:

okay, try accessing one of your tables in the database. e.g.: http://localhost/berkeleywv-fe-inspections/table.json e.g.: http://localhost/berkeleywv-fe-inspections/table.xml e.g.: http://localhost/berkeleywv-fe-inspections/table.html

— Reply to this email directly or view it on GitHub.

layer67tech commented 10 years ago

Absolutely a database connection to web server issue. This is usually resolved by changing your database binding in the my.cnf configuration. e.g.: #bind-address = 127.0.0.1

wvmikep commented 10 years ago

Not so fast: http://data.mike-pulsifer.org/test.php

Sent from my iPhone

On Mar 1, 2014, at 11:17 PM, "Patrick K. Johnson Jr." notifications@github.com wrote:

Absolutely a database connection to web server issue. This is usually resolved by changing your database binding in the my.cnf configuration. e.g.: #bind-address = 127.0.0.1

— Reply to this email directly or view it on GitHub.

layer67tech commented 10 years ago

Problem with code. Does not work that way. test.php cannot be converted to REST http://avizium.no-ip.org/apiv2/avizium-bloggers/av_comments.xml

wvmikep commented 10 years ago

I know. It just proves I can get to the db.

Sent from my iPhone

On Mar 2, 2014, at 7:17 AM, "Patrick K. Johnson Jr." notifications@github.com wrote:

Problem with code. Does not work that way. test.php cannot be converted to REST http://avizium.no-ip.org/apiv2/avizium-bloggers/av_comments.xml

— Reply to this email directly or view it on GitHub.

phoenixg commented 10 years ago

Have you solved that? I meet the same problem.

waldoj commented 10 years ago

FWIW, I've been unable to replicate the problem.

jamespsterling commented 9 years ago

@alpheustechnologies You're saying we have to edit the config.php and class.db-api.php. Why have a config file then?

bunlongheng commented 8 years ago

@I faced the same problem.

I've followed all the comments in this post, and still see

Must select a database


I've used the same settings in MySQL Workbench and I can connect to my db fine.


What should I put for dataset-name ?

ersoviet commented 6 years ago

same problem!

MelanieFirefly commented 4 years ago

You do not need to edit class.db-api.php. You need to edit config.php and .htaccess to fit your configuration:

config.php: change $defaults = array to your db info register_db_api( 'whateveryouwanttonameyourdataset', $args );

.htaccess:

RewriteEngine On RewriteBase /folderyoumadeforthisproject/ then to access whateveryouwanttonameyourdataset dataset go to yourdomain.com/folderyoumadeforthisproject/whateveryouwanttonameyourdataset/yourtablename.json
Anymfah commented 3 years ago

.htaccess RewriteBase was wrong for me :) Changed it to my project path, ty man.