Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this mean?

I found this in some code examples while googling :

$sql = 'INSERT INTO users (username,passwordHash) VALUES (?,?)';

it's new to me, but I would guess that it a substitution method and equivalent to

$sql = "INSERT INTO users (username,passwordHash) VALUES ($username,$passwordHash)";` 

or

$sql = 'INSERT INTO users (username,passwordHash) VALUES (' . $username . ',' . $passwordHash . ')';`

would that be correct? Is it an actual PHP syntax, or was he just trying to simplify his example?


Thanks for the feedback, folks

like image 429
Mawg says reinstate Monica Avatar asked Jan 08 '11 06:01

Mawg says reinstate Monica


People also ask

What does that mean is correct?

correct, exact, and accurate mean agreeing with a fact, truth, or standard. correct is used for something that contains no errors.

How do you mean VS What do you mean?

What do you mean? is commonly known and usually said when one does not comprehend what the other said. Basically it is asking for a repeat of the sentence in more detail. How do you mean? is a little different. How can be defined as in what way or manner.


1 Answers

This is pretty common in prepared statements. The ? merely serves as a placeholder, as seen below from the PHP documentation:

$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (?, ?)");
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $value);

// insert one row
$name = 'one';
$value = 1;
$stmt->execute();

// insert another row with different values
$name = 'two';
$value = 2;
$stmt->execute();
like image 137
Sampson Avatar answered Oct 28 '22 21:10

Sampson