1

In php manual http://php.net/manual/en/mysqli-stmt.bind-param.php

I see code like this:

$stmt->bind_param('sssd', $code, $language, $official, $percent);

$code = 'DEU';
$language = 'Bavarian';
$official = "F";
$percent = 11.2;

/* execute prepared statement */
$stmt->execute();
1

2 Answers 2

2

The bind_param() method stores references to the values of the $code, $language, $official and $percent variables. The references are stored inside the $stmt object.

When you then give the variables values the $stmt object already knows where to look for the values.

We can create a class, that does this, ourselves:

class Play {
    protected $reference;
    public function bind( & $variable) {
        $this->reference = &$variable;
    }
    public function show() {
        echo "{$this->reference}<br>\n";
    }
}

The & character is the reference operator. When you use it you get a reference to the value of another variable.

With this class we can create an object and have some fun:

$play = new Play;
$play->bind($string);

$string = 'Hello!';
$play->show();

$string = 'World!';
$play->show();
Sign up to request clarification or add additional context in comments.

Comments

-1

No php can't use a variable before you write the declaration!

No language is obviously able to output a value, before it exists.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.