Re: A prepared statements question

From: Date: Sun, 12 Jul 2009 20:32:55 +0000
Subject: Re: A prepared statements question
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-295300@lists.php.net to get a copy of this message
>  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 :)

« previous php.general (#295300) next »