How to convert this to PDO?

How do I convert the following part from mysqli to pdo:


$row = mysqli_fetch_assoc(mysqli_query($con,'SELECT now() as now'));

    while(!$newData && (time()-$timeStart)<20){
 
	// check for new data
	$result = mysqli_query($con,$sql);
	while($row = mysqli_fetch_assoc($result)){
		$notifications[] = $row;
		$newData = true;
	}
	// let the server rest for a while
	usleep ( 500000 );
}

Thank you in advance

After connecting, and supposing your connection is names $conn:


$qry = 'SELECT now() as now';
$stmt = $conn->prepare($qry);
$stmt->execute();
while(!$newData && (time()-$timeStart)<20){
 
    // check for new data
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
        $notifications[] = $row['now'];
        $newData = true;
    }
    // let the server rest for a while
    usleep ( 500000 );
}  

I haven’t tested this. But it something along those lines.