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

Ds\Map do not support mysqli result fetch_object #79

Open
breath-co2 opened this issue Mar 22, 2017 · 5 comments
Open

Ds\Map do not support mysqli result fetch_object #79

breath-co2 opened this issue Mar 22, 2017 · 5 comments
Labels

Comments

@breath-co2
Copy link

<?php
$mysql = new mysqli('localhost', 'root', '***', 'test');
$rs = $mysql->query('select * from `mydb` limit 10');
while ($row = $rs->fetch_object('\\Ds\\Map'))
{
    print_r($row);
}

output:

PHP Recoverable fatal error:  Object of class Ds\Map could not be converted to boolean in /test.php on line 4
<?php
$mysql = new mysqli('localhost', 'root', '***', 'test');
$rs = $mysql->query('select * from `mydb` limit 10');
while (null !== ($row = $rs->fetch_object('\\Ds\\Map')))
{
    print_r($row);
    var_dump($row->id);
    var_dump(isset($row['id']));
}

output:

Ds\Map Object
(
)
string(1) "1"
bool(false)
Ds\Map Object
(
)
string(1) "2"
bool(false)
@rtheunissen
Copy link
Member

I believe this is because Ds\Map doesn't use the object's properties table to store the data. I don't see a way to support this, sorry. Could just fetch as array and create map using that data.

@breath-co2
Copy link
Author

@rtheunissen thank you.

If it implement magic method __set($key, $value) can support it, like this php code:

class Ds\Map
{
    function __set($key, $value)
    {
        $this[$key] = $value;
    }
}

or Ds\Map implement the ArrayAccess interface. It's my imagine.

@rtheunissen
Copy link
Member

I'm not sure if array access would solve this. What you could do is create a class like ResultMap that creates an instance of Ds\Map and gets/sets on that instance using its own __get and __set. That way you can fetch into ResultMap and expose a get() method to return the internal map.

Might be faster to just fetch an array and instantiate a new map with it, will need to benchmark that yourself to see what works best for you.

@rvanvelzen
Copy link
Contributor

This might also be related (and fixed) to #62

@rtheunissen
Copy link
Member

#62 fixes the boolean cast issue but we still can't fetch into any of the structures.

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

No branches or pull requests

3 participants