Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

use prepared statement in a where clause PDO

	$servername = "localhost";
	$username = "root";
	$password = "toor";
	$dbname = "testdb";
    $user = 'admin';
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $conn->prepare("SELECT * FROM radcheck where username = :username ");
    $stmt->bindParam(':username', $user);
    $stmt->execute();

    // set the resulting array to associative
//    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    $counter = $stmt->fetchAll();
    echo "Total rows returned" .count($counter);
 
PREVIOUS NEXT
Tagged: #prepared #statement #clause #PDO
ADD COMMENT
Topic
Name
4+6 =