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

PHP Fatal error: Uncaught Error: Call to a member function write() on null in /code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php:257 #76

Closed
factormaarten opened this issue Nov 19, 2018 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@factormaarten
Copy link

factormaarten commented Nov 19, 2018

Hi there,

I'm testing my code on vagrant instances. Now I have Rethink running on one vm, and my code on another vm.

The db is up and running and I can access it via my browser. However inside of the code nothing happens when I run:

$connections = [
    'default' => new Options([
        'hostname' => '<internal ip>',
        'port' => 28015,
        'dbname' => 'vagrant',
        'user' => '...',
        'password' => '...'
    ]),
];
$registry = new Registry($connections);

$r = new Rethink($registry->getConnection('default'));
$r->table('trades')
  ->insert([
      [
          'documentId' => 1,
          'title' => 'Test document',
          'description' => 'My first document.'  
      ],    
  ])
  ->run();

The table exists, the stream is created and connected in socket, however I still get the following:

PHP Fatal error:  Uncaught Error: Call to a member function write() on null in /code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php:257
Stack trace:
#0 /code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php(163): TBolier\RethinkQL\Connection\Connection->writeQuery(588962815, Object(TBolier\RethinkQL\Message\Message))
#1 /code/vendor/tbolier/php-rethink-ql/src/Query/AbstractQuery.php(32): TBolier\RethinkQL\Connection\Connection->run(Object(TBolier\RethinkQL\Message\Message))
#2 /code/bin/OrderBook.php(33): TBolier\RethinkQL\Query\AbstractQuery->run()
#3 {main}
  thrown in /code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php on line 257
@factormaarten factormaarten changed the title How can I test my connection? PHP Fatal error: Uncaught Error: Call to a member function write() on null in /code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php:257 Nov 19, 2018
@tbolier tbolier added the bug Something isn't working label Nov 19, 2018
@tbolier tbolier self-assigned this Nov 19, 2018
@tbolier tbolier added this to the Version 2.0 milestone Nov 19, 2018
@tbolier
Copy link
Owner

tbolier commented Nov 19, 2018

Hi @mpjraaij

Before you execute the query, please execute $r->connection()->connect();

The fatal error that caused your error is related to not having connected first, so there is no open stream.

I have updated the code, to throw a proper ConnectionException in that case. I've also updated the documentation which was missing the $r->connection()->connect(); reference.

Thanks for reporting this.
You can immediately fix your issue with your current version of the library by connecting first.

Let me know if that sorted it for you?

Cheers

@tbolier
Copy link
Owner

tbolier commented Nov 20, 2018

This issue has been resolved.

@tbolier tbolier closed this as completed Nov 20, 2018
@factormaarten
Copy link
Author

factormaarten commented Nov 20, 2018

Thanks!

That did not fully solve it. To test I'm now using this code:

$r = new Rethink($registry->getConnection('default'));
$r->connection()->connect();
$r->db()
  ->tableCreate('test')
  ->run();

I'm getting a Runtime Error:

PHP Fatal error:  Uncaught TBolier\RethinkQL\Connection\ConnectionException: Runtime error: U, jsonQuery: [1,[60,[[1,"test"]]],{"db":[14,["vagrant"]]}] in/code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php:372
Stack trace:
#0 /code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php(334): TBolier\RethinkQL\Connection\Connection->validateResponse(Object(TBolier\RethinkQL\Response\Response), 820726866, 820726866, Object(TBolier\RethinkQL\Message\Message))
#1 /code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php(169): TBolier\RethinkQL\Connection\Connection->receiveResponse(820726866, Object(TBolier\RethinkQL\Message\Message))
#2 /code/vendor/tbolier/php-rethink-ql/src/Query/AbstractQuery.php(32): TBolier\RethinkQL\Connection\Connection->run(Object(TBolier\RethinkQL\Message\Message))
#3 /code/bin/OrderBook.php(28): TBolier\RethinkQL\Query\AbstractQuery->run()
#4 {main}

Next TBolier\RethinkQL\Connection\ConnectionException: Runtime error: U, jsonQuery: [1,[60,[[1,"test"]]],{"db":[14,["vagrant"]] in /code/vendor/tbolier/php-rethink-ql/src/Connection/Connection.php on line 181

This is because I did not grant the permissions to the user yet. Might need a different error message.

@tbolier
Copy link
Owner

tbolier commented Dec 3, 2018

...
This is because I did not grant the permissions to the user yet. Might need a different error message.

Thanks I have created a new issue for that one here: #78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants