phalcon-rest icon indicating copy to clipboard operation
phalcon-rest copied to clipboard

Why I can't connect to mysql?

Open piavgh opened this issue 10 years ago • 3 comments

Hi everyone, I've used Phalcon micro for a couple of months, and now I want to switch to something more RESTful, and I found this repo https://github.com/cmoore4/phalcon-rest

  1. I've declared database parameters in config.ini

    [database]
    adapter  = Mysql
    host     = localhost
    username = test
    password = test
    name     = test
  2. I've set the di to connect to db

    $di->set('db', function() use ($config) {
    $dbclass = 'Phalcon\Db\Adapter\Pdo\\' . $config->database->adapter;
    return new $dbclass(array(
        "host"     => $config->database->host,
        "username" => $config->database->username,
        "password" => $config->database->password,
        "dbname"   => $config->database->name
    ));
    });
  3. Class Princesses.php in is models folder

  4. When I tried to add this line

    $princesses = Princesses::find();
    in the ExampleController.php, I got the blank page when going to host/v1/example. When I removed that line, everything is fine.

What is the problem here?

Thank you very much. Any help is appreciated!

piavgh avatar Feb 27 '15 03:02 piavgh

In model directory file with class has name Princess.php, but class has name Princesses: ... use \PhalconRest\Exceptions\HTTPException;

class Princesses extends \Phalcon\Mvc\Model{ ... Rename class to Princess and check all references to this class in code.

dmytrome avatar Sep 10 '15 10:09 dmytrome

hi please describ how to get data from mysql in this project i want to select data from my mysql db

can you help me????

mosiera98 avatar Jan 23 '16 11:01 mosiera98

can u help me and future user? i got same error.

kevinzie avatar Aug 23 '17 17:08 kevinzie