Oto Shavadze
Oto Shavadze

Reputation: 42773

PDO errorinfo with user which has no privilege

I set on mysql user only SELECT privilege

Then, When I run UPDATE ... query

$sth = $db->prepare( $update_sql );

if (!$sth) {
    echo "fail";
}
else {
    echo "Ok";
}

Printed Ok, though in table nothing updated.

Question: Why printed Ok and not fail ?

Upvotes: 0

Views: 47

Answers (2)

symcbean
symcbean

Reputation: 48357

...because you didn't execute the statement - you only prepared it.

function try_to_run($sql, $db)
{
   $sth = $db->prepare( $update_sql );
   if (false===$sth) return false;
   $r=$sth->execute();
   return $r;
}

if (false===try_to_run($sql, $db)) {
   echo "fail";
} else {
   echo "Ok";
}

Upvotes: 1

tadman
tadman

Reputation: 211610

You probably need to execute the query you've prepared:

$sth->execute();

The prepared statement itself does not do anything on the database. The documentation provides more specifics.

Remember the exceute call is when you can bind your SQL placeholder values.

Upvotes: 3

Related Questions