Last active
January 2, 2016 07:59
-
-
Save davidchc/8273759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pdo = new PDO("mysql:host=localhost;dbname=vendas", "root", ""); | |
$stmt = $pdo->prepare("SELECT * FROM produtos"); | |
$stmt->execute(); | |
$rows = $stmt->fetchAll(PDO:FETCH_ASSOC); | |
$total = 0; | |
foreach($rows as $produto){ | |
$total += $produto['preco']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pdo = new PDO("mysql:host=localhost;dbname=vendas", "root", ""); | |
$sql = "SELECT SUM(preco) AS total FROM produtos"; | |
$stmt = $pdo->prepare($sql); | |
$stmt->execute(); | |
$row = $stmt->fetch(PDO:FETCH_ASSOC); | |
echo "Total ".$row['total']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment