/    Sign up×
Community /Pin to ProfileBookmark

PDO Questions on -> & =>

Reading on pdo.

What are these for and what do they mean ? I still on procedural style programming.
->
=>

For example:

[code]
$stmt = $pdo->prepare(‘SELECT * FROM users WHERE email = ? AND status=?’);
$stmt->execute([$email, $status]);
$user = $stmt->fetch();
// or
$stmt = $pdo->prepare(‘SELECT * FROM users WHERE email = :email AND status=:status’);
$stmt->execute([’email’ => $email, ‘status’ => $status]);
$user = $stmt->fetch();
[/code]

What does this mean ?

[code]
$user = $stmt->fetch();
[/code]

Ok, it means, after fetching the result, dump it onto $user.
But what exactly “->” mean ? Does it mean “do this afterwards” or “do this after that” ?

to post a comment

7 Comments(s)

Copy linkTweet thisAlerts:
@developer_webauthorMay 20.2020 — Folks,

Why is there a space on the first one but not the last one ?
<i>
</i>$stmt = $pdo-&gt;prepare('SELECT * FROM users WHERE email = ? AND status=?');


Again here:
<i>
</i>$stmt = $pdo-&gt;prepare('SELECT * FROM users WHERE email = :email AND status=:status


Look at the placeholders.

The codes are from this tutorial:

https://phpdelusions.net/pdo
Copy linkTweet thisAlerts:
@NachfolgerMay 20.2020 — @developer_web#1618618

This has nothing to do with PDO or databases, and everything to do with PHP. You can dig into it further on your own, so here's the simple explanation.

  • 1. =&gt; is an assignment operator. Typically used in arrays, as you have done here: ['email' =&gt; $email, 'status' =&gt; $status]

  • 2. -&gt; is an access "operator". This is used specifically to access a object's property. As you have done in: $pdo-&gt;prepare, $stmt-&gt;fetch, and $stmt-&gt;execute. You're calling the prepare, fetch, and execute functions of the PDO statement object.


  • These are just generic examples of both -&gt; and =&gt;. They can do more than these things.
    Copy linkTweet thisAlerts:
    @NogDogMay 20.2020 — > @developer_web#1618618 Why is there a space on the first one but not the last one ?

    Because the spaces are optional. This even allows you to nicely format your sql:
    <i>
    </i>$sql = "
    SELECT *
    FROM some_table
    WHERE
    some_column = ? AND
    another = ? AND
    yet_another_col = ?
    ";
    Copy linkTweet thisAlerts:
    @developer_webauthorMay 20.2020 — Shall I tell you why I am still struggling at procedural style programming and not got into oop yet ? Cos (because) I don't understand what an 'object' is. No matter how many tutorials I have read, I don;t understand it.

    Maybe, someone here can enlighten me in layman's lang ?

    Explain to me in layman's talk, the difference between procedural style programming and oop.

    Then I should get somewhere if I can manage to understand you.
    Copy linkTweet thisAlerts:
    @developer_webauthorMay 20.2020 — @NogDog#1618632

    Ok. I understand. Spaces optional. But why on both examples the tutor decided to have spaces on the 2nd placeholder ?
    Copy linkTweet thisAlerts:
    @NogDogMay 20.2020 — > @developer_web#1618636 why on both examples the tutor decided to have spaces on the 2nd placeholder ?

    You'll have to ask them. There's no functional difference.
    Copy linkTweet thisAlerts:
    @NogDogMay 20.2020 — @developer_web#1618635

    For some really general concepts, check out https://docs.oracle.com/javase/tutorial/java/concepts/index.html . Yes, it's for Java, not PHP, but the syntax is similar, and all you really want to look at there is the conceptual stuff in the first couple of sections: "What is an object?" and "What it a class?". The key take-away is the idea that a "class" defines something that you want to model in your code, while an "object" is a specific instance of a class. (In their example, you can define a Bicycle class, then instantiate any number of objects from it to represent specific Bicycle objects -- maybe representing each bike being ridden in the Tour of France?)

    The stuff on "inheritance" and then "interfaces" is good to know, but you won't need it right away, most likely. Don't even bother with the "package" stuff, as that's Java-specific.

    Maybe with those basic concepts in place, some of the PHP-specific tutorials will make more sense? But ultimately we're talking about software programming concepts here, stuff people go to school for and don't just pick up from a 45-minute YouTube video or such. Matt Zandstra's _PHP Objects, Patterns, and Practice_ book taught me a lot, but you have to commit the time to read and digest it -- not just rush through it and assume you'll then be an expert.
    ×

    Success!

    Help @developer_web spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.23,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...