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

Fixing the example xpdo.query #408

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open

Fixing the example xpdo.query #408

wants to merge 1 commit into from

Conversation

Ibochkarev
Copy link
Collaborator

Description

Fixing the example xpdo.query

Affected versions

both

Relevant issues

#391

@Ibochkarev Ibochkarev requested a review from Mark-H May 15, 2022 05:23
@@ -37,12 +37,11 @@ The SQL statement to prepare and execute. Data inside the query should be [prope

```php
$result = $modx->query("SELECT * FROM modx_users WHERE id=1");
if (!is_object($result)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe $modx->query will return false if the query is somehow invalid, perhaps also if there are issues connecting to the database. So while that shouldn't happen in this particular example, it is important to check the $result is an object. IIRC it's a \PDOStatement object.

if(!$result->fetch(PDO::FETCH_ASSOC)) {
return 'No result!';
} else {
$row = $result->fetch(PDO::FETCH_ASSOC);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is the second time $result->fetch() is called, if there are multiple results (there wont be in this example) this will return the second rather than the first one.

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

Successfully merging this pull request may close these issues.

2 participants