Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the equivalent of bind_result on PDO
    text
    copied!<p>I'm converting to PDO and Im using prepared statements, I want to bind my result as so <code>$stmt-&gt;bind_result($email_count);</code> so i am able to put this into an if statement to see if the e-mail exists however I am getting the error <code>Fatal error: Call to undefined method PDOStatement::bind_result() in /Applications/XAMPP/xamppfiles/htdocs/imanage/insert.php on line 51</code> which relates to the previous example. </p> <p>I'm guessing bind_result is not a PDO defined method, so is there an equivalent I could use?</p> <p>My code is below in case it helps:</p> <p>insert.php</p> <pre><code>&lt;?php include("connect/class.Database.php"); class Users extends Database { public function insert() { $stmt = $this-&gt;pdo-&gt;prepare("SELECT COUNT(*) FROM users WHERE email=:email"); $stmt-&gt;bindParam(":email", $_POST['email']); $stmt-&gt;bind_result($email_count); $stmt-&gt;execute(); $stmt-&gt;fetch(PDO::FETCH_ASSOC); if ($email_count &gt; 0) { echo "email exisits! click here to try &lt;a href='register'&gt;again&lt;/a&gt;"; } else { //escape the POST data for added protection $username = isset($_POST['username']) ? $_POST['username'] : null; $cryptedPassword = crypt($_POST['password']); $password = $cryptedPassword; $name = isset($_POST['name']) ? $_POST['name'] : null; $email = isset($_POST['email']) ? $_POST['email'] : null; $data = array($username, $password, $name, $email); $stmta = $this-&gt;pdo-&gt;prepare("INSERT INTO users (username, password, name, email) VALUES (?, ?, ?, ?)"); $stmta-&gt;execute($data); printf("%d Row inserted.\n", $stmta-&gt;row_count); /* close statement and connection */ $stmta-&gt;close(); } // end email_count and insert to table } // end function } ?&gt; </code></pre> <p>connect/class.Database.php</p> <pre><code>&lt;?php // Database connection PDO class Database { public function __construct() { // Connection information $host = 'localhost'; $dbname = 'imanage'; $user = 'root'; $pass = ''; // Attempt DB connection try { $this-&gt;pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); $this-&gt;pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo 'Successfully connected to the database!'; } catch(PDOException $e) { echo $e-&gt;getMessage(); } } public function __destruct() { // Disconnect from DB $this-&gt;pdo = null; echo 'Successfully disconnected from the database!'; } } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload