php-sql-query-builder: tutorial doesn't work
PHP 7.0
->setTable('user')
->setColumns(['userId' => 'user_id', 'username' => 'name', 'email' => 'email']);
echo $builder->write($query);
`
``` [Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Argument 1 passed to NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder::write() must implement interface NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface, instance of NilPortu
gues\Sql\QueryBuilder\Manipulation\ColumnQuery given, `
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 15 (3 by maintainers)
Commits related to this issue
- Merge pull request #96 from mmuhasan/dev-where-bug-fix Fix the where clause issue to solve issue #73 — committed to nilportugues/php-sql-query-builder by nilportugues 6 years ago
Can u fix this shit?
I researched a little and discovered that the core isn’t soo hackable, see an example: If i create the SQL Instruction directly by invoking the correspondent methods, as an example
where()andsetColumns()statement, they return respectivelyWhereandColumnQueryclass instances.Generating the following error:
I simply used.
$query = $builder->select()->setTable('DEVICES')->setColumns($deviceArray)->where()->equals('ID', 7); $builder->write($query);as example, and the error ahead was returned to me.
BUT, if i do in this way:
$parteOne = $builder->select()->setTable('DEVICES'); $parteOne->setColumns($deviceArray); $parteOne->where()->equals('ID', 7); $builder->write($parteOne);Everything works correctly. Maybe your Variable Injection isn’t working correctly.
After looking through the tests, all of which pass, there is a key difference in how the queries are built up in the tutorials. Rather than calling
builder->select()to initialise the query, create a new instance of theSelectclass instead. The first example should actually read:Following this method all of the examples I’ve tried so far do indeed work.
I know this project is no longer maintained, but it is an awesome project and this might help someone else who wants to use it 😃
Why can this still be open? Would be cool to get it solved asap.
I had to add
Then i can do something like this:
It’s not the best thing but it’s the only workaround I found.
@nilportugues what you think can be? The tutorial is a demonstration? or is intended to wisely work? I didn’t give a look in the source code of this library, but i think that’s a bug?
Since also phpStorm is warning me that the return types of the variables aren’t the expected as the tutorial…
Confirmed here, too.