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

Error when trying to use $db->vardump() #163

Closed
dpDesignz opened this issue Aug 13, 2019 · 6 comments · Fixed by #166
Closed

Error when trying to use $db->vardump() #163

dpDesignz opened this issue Aug 13, 2019 · 6 comments · Fixed by #166
Labels
error-bug Issues causing application termination. warning-bug Issues not causing scripts/routines to die/fail.

Comments

@dpDesignz
Copy link
Contributor

dpDesignz commented Aug 13, 2019

Describe the bug
I tried to use the $db->vardump() method because the $db->debug() method wasn't spitting anything out, and I got the following error: Object of class stdClass could not be converted to string in \vendor\ezsql\ezsql\lib\ezsqlModel.php:462

To Reproduce
Using PDO connection

$db = Database::initialize('pdo', ['mysql:host=localhost;dbname=example;charset=utf8mb', 'user', 'password']);
$db->prepareOn();

Then tried to run selecting

// Get 'user_id', 'user_password', 'user_password_key', and 'user_auth_rqd' from 'cs_users' table that match entered $userData
$result = $db->selecting('users', 'user_id, user_password, user_password_key, user_auth_rqd', eq('user_login', $userData, _OR ), eq('user_email', $userData ) );
$db->debug();
echo '<pre>';
$db->vardump($result);
echo '</pre>';
exit;

Expected behavior
I expected the debug screen to come up (which nothing comes up, even if I don't try to run the vardump method) and the vardump to output some data (this is where an error pops up).
If I remove both of the methods I can see the object results using a standard var_dump($result); so I know the query is executing, I just can't get the debug to actually show me anything and I can't get the vardump to output as I get the error mentioned above.

Environment (please complete the following information):

  • EZSQL Version : 4
  • PHP Version: 7.3.1
  • SQL Driver: mysql
@dpDesignz dpDesignz added error-bug Issues causing application termination. warning-bug Issues not causing scripts/routines to die/fail. labels Aug 13, 2019
@TheTechsTech
Copy link
Contributor

You need to turn on debug outputting currently it's off by default.
I will add methods to do that much simpler, than $db->setDebug_Echo_Is_On(true); which you need to do until it's added.

The error must be referring to $this->last_result[0] call. Your example do look correct, seem the as in unit test here:

public function testSelecting()

Will need more info to track down.

@dpDesignz
Copy link
Contributor Author

Ah, thanks, that would be why. I didn't see that function in any of the documentation or the phpunit test files. I've updated the documentation in the Wiki to reflect your notes for future people 😄

Ok so now the debug is working, I'm still getting that error. What more information do you require from me and I'll send it through. This is exactly what I get:

ErrorException: 0 Object of class stdClass could not be converted to string. File: \vendor\ezsql\ezsql\lib\ezsqlModel.php:478 (Line row has changed as I've implemented your new code for the debug method)

I did some echoing the line above and returns an array. the line in question is as follows:

echo "<b>Last Rows Returned:</b> ".((\count($this->last_result) > 0) ? $this->last_result[0] : '')."\n";

The code that's throwing back the error is the $this->last_result[0] because the echo is trying to convert it to a string where it's an array and it can't convert it.

I changed the line to echo "<b>Last Rows Returned:</b> ".((\count($this->last_result) > 0) ? print_r($this->last_result[0]) : '')."\n"; and it didn't fail, but I'm not sure what it's supposed to return so I'm not sure if that's fixed it or not.

@TheTechsTech
Copy link
Contributor

TheTechsTech commented Aug 17, 2019

You getting the error because you are proceeding thinking you got valid results already. Check $result for false or 0, which it will be.
As commented in #164, need an example of it working like you want without using any shortcuts methods.

I changed the line to echo "Last Rows Returned: ".((\count($this->last_result) > 0) ? print_r($this->last_result[0]) : '')."\n"; and it didn't fail, but I'm not sure what it's supposed to return so I'm not sure if that's fixed it or not.

No fix, it should return the results of the last successful query. which you are not getting.

@dpDesignz
Copy link
Contributor Author

You getting the error because you are proceeding thinking you got valid results already. Check $result for false or 0, which it will be.
As commented in #164, need an example of it working like you want without using any shortcuts methods.

I changed the line to echo "Last Rows Returned: ".((\count($this->last_result) > 0) ? print_r($this->last_result[0]) : '')."\n"; and it didn't fail, but I'm not sure what it's supposed to return so I'm not sure if that's fixed it or not.

No fix, it should return the results of the last successful query. which you are not getting.

Not correct, it fails no matter what my query is.

I tried this code which still gives me the same error

$userData = 'dpdesignz';

$result = $db->get_row("SELECT * FROM users WHERE user_login='$userData'");

$db->varDump($result);

But if I run the debug it returns

ezSQL (v4.0.5) Debug..

Query [7] --[SELECT * FROM users WHERE user_login='dpdesignz' ]

Query Result.. 

(row) 1... etc

So I know the SQL is returning a result. The issue is that the value of $result is an object as outlined below from the documentation

Most ezsql functions can return results as Objects, Associative Arrays, Numerical Arrays or Json Encoded.

You can't echo out an object (or array) which is what the line of code that is giving the error is doing

echo "<b>Last Rows Returned:</b> ".((\count($this->last_result) > 0) ? $this->last_result[0] : '')."\n";

But adding in the print_r() or var_dump() allows it to print out the object (or array)

@TheTechsTech
Copy link
Contributor

You should submit PR.

@dpDesignz
Copy link
Contributor Author

This is my first time doing a PR so hopefully that's right 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-bug Issues causing application termination. warning-bug Issues not causing scripts/routines to die/fail.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants