Re: A prepared statements question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>  if (   $link = mysqli_connect($hostname, $username, $password, $database)
>      && $stmt = mysqli_prepare($link, $q)
>      &&         mysqli_stmt_bind_param($stmt, "s", $adminuser)
>      &&         mysqli_stmt_execute($stmt)
>      &&         mysqli_stmt_store_result($stmt))
>  {
>    $count = mysqli_stmt_num_rows($stmt);
>  } else {
>    /* Of course, at this point it would be nice to know which
>       function failed. I don't think there is a neat way to
>       find that out, and checking every function for errors
>       would make the code look much much worse than using the
>       old mysql[i]_query functions. Bleah. */
>  }
>
>
> /Nisse
>

Not to sort of start (another) holy war on this list, but it's ugly
blocks of code like this that pushed me into using PDO.

This, IMO, is so much easier to read:

try {
  $stmt = $pdo->prepare();
  $stmt->bindValue();
  $stmt->execute();
  $stmt->numRows();
} catch (PDOException $p) {
  //do stuff
}

I would much rather try/catch exceptions than clutter up code with
hundreds of if/elseif/else statements.

This is just my opinion, of course :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux