I have the basic of basic of codes
My bootstrap file
<?php
//...
use Phalcon\Db\Adapter\Pdo\Sqlite as DbAdapter;
//...
// Setup the database service
$di->set('db', function () {
return new DbAdapter([
"dbname" => "/Users/saginadir/sqlite/vmessages.sqlite"
]);
});
My Users Model file
<?php
use Phalcon\Mvc\Model;
class Users extends Model
{
public $id;
public $name;
public $email;
public function initialize()
{
$this->setConnectionService('db');
}
}
My DB table:
CREATE TABLE users
(
id INTEGER PRIMARY KEY,
name TEXT,
email TEXT
);
My Controller file
<?php
use Phalcon\Mvc\Controller;
class UsersController extends Controller
{
public function getUser()
{
$userFromQuery = $this->di->get('db')->fetchOne("SELECT * FROM users WHERE name = 'John'");
$users = new Users();
$user = $users->findFirst(["name" => "John"]);
var_dump($user); // id = 1 DIFFERENT ID FROM BELOW!
var_dump($userFromQuery); //id = 2 DIFFERENT ID FROM ABOVE!
}
}
In the case above, when i fetch a row using my db connection I get id = 2, which is correct, but when I try to fetch rows using my model, I get id = 1, all the time.
Anyone has this issue? am I doing something wrong?