/* * * MySQLi procedural * MySQLi orientat a objectes * PDO * * MySql MySqli PDO */ $sql = "insert into clientes (mail,password) values (:mail,:password)"; $st = $conn->prepare($sql); $st->execute(array(':mail' => 'pepe@pepe.com', ':password' => '1234')); $sql = "SELECT count(idproductos) as total FROM productos"; $st = $conn->prepare($sql); $st->execute(); $row = $st->fetch(); echo "El número de productos es: " . $row['total'] . "<br/>"; $sql = "SELECT sum(importe) as total FROM pedido"; $st = $conn->prepare($sql); $st->execute(); $row = $st->fetch(); echo "La suma de los importes de los pedidos es: " . $row['total'] . "<br/>"; $sql = "delete from productos where idproductos=:idproductos"; $st = $conn->prepare($sql); $st->execute(array(':idproductos' => 5)); $sql = "SELECT mail FROM clientes"; $st = $conn->prepare($sql); $st->execute(); while ($row = $st->fetch()) { echo $row['mail'] . "<br/>"; } $sql = "SELECT mail FROM clientes where mail like '%@gmail.com'"; $st = $conn->prepare($sql); $st->execute(); while ($row = $st->fetch()) { echo $row['mail'] . "<br/>"; } $sql = "insert into clientes (mail, password) values (:mail, :password)"; $st = $conn->prepare($sql); for ($i = 0; $i < 10; $i++) $st->execute(array(':mail' => 'test@test.com', ':password' => '1234')); function import_total_IVA($idclient) { global $conn; try { $sql = "select sum(import*(1+iva)) as total from comandes join clients using (idclients) where idclients=:idclients"; $stmt = $conn->prepare($sql); $stmt->execute(array(':idclients' => $idclient)); $fila = $stmt->fetch(); $total = $fila['total']; return $total; } catch (Exception $ex) { return 0; } }