Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Must select a database" #14

Open
wvmikep opened this issue Mar 1, 2014 · 19 comments
Open

"Must select a database" #14

wvmikep opened this issue Mar 1, 2014 · 19 comments

Comments

@wvmikep
Copy link

wvmikep commented Mar 1, 2014

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
Copy link

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
Copy link
Author

wvmikep commented Mar 2, 2014

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
Copy link

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
Copy link
Author

wvmikep commented Mar 2, 2014

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
Copy link

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
Copy link
Author

wvmikep commented Mar 2, 2014

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
Copy link

@wvmikep
Copy link
Author

wvmikep commented Mar 2, 2014

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
Copy link

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
Copy link
Author

wvmikep commented Mar 2, 2014

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
Copy link

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
Copy link
Author

wvmikep commented Mar 2, 2014

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
Copy link

Have you solved that? I meet the same problem.

@waldoj
Copy link
Contributor

waldoj commented Apr 18, 2014

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

@jamespsterling
Copy link

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

@bunlongheng
Copy link

bunlongheng commented Aug 9, 2016

@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
Copy link

same problem!

@MelanieFirefly
Copy link

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
Copy link

Anymfah commented May 13, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants