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 | |
/*$direccion = "localhost"; | |
$usuario = "root"; | |
$contrasenia= ""; | |
$BD = "gestion_bd_clase"; | |
$conn = new mysqli($direccion, $usuario, $contrasenia, $BD);*/ | |
/*$driver = 'mysql'; |
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 | |
if (isset($_GET['Enviar'])) { | |
//=============CONECTAR A DATA BASE============================================ | |
try { | |
$conn = new PDO('mysql:host=localhost;port=3307;dbname=operaciones', 'root', 'contrasena'); | |
}catch(PDOException $e){ |
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
VIDEO: https://web.microsoftstream.com/video/49b5dd09-a8c1-41c4-926c-c46307678d78 | |
========== CÓDIGO PHP ========== | |
<?php | |
//=============CONECTAR A DATA BASE============================================ | |
try { |
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
#Con IF | |
DELIMITER $$ | |
CREATE PROCEDURE `sp_fail`() | |
BEGIN | |
DECLARE `_rollback` BOOL DEFAULT 0; | |
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET `_rollback` = 1; | |
START TRANSACTION; | |
INSERT INTO `tablea` (`date`) VALUES (NOW()); | |
INSERT INTO `tableb` (`date`) VALUES (NOW()); |
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 | |
// this procedures must exts in db | |
//======================================== | |
// Drop procedure if exists ProcSuma; | |
// DELIMITER // | |
// CREATE PROCEDURE ProcSuma(IN nm1 INT, IN nm2 INT, OUT value INT) | |
// BEGIN | |
// SET value = nm1+nm2; | |
// END // |
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 | |
/*$direccion = "localhost"; | |
$usuario = "root"; | |
$contrasenia= ""; | |
$BD = "gestion_bd_clase"; | |
$conn = new mysqli($direccion, $usuario, $contrasenia, $BD);*/ | |
/*$driver = 'mysql'; |
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
DROP FUNCTION IF EXISTS operacionesif; | |
DELIMITER // | |
CREATE FUNCTION operacionesif(op INT, num1 INT, num2 INT) | |
RETURNS VARCHAR(255) DETERMINISTIC | |
BEGIN | |
IF op=1 THEN | |
RETURN CONCAT(num1,' + ',num2,' = ',num1+num2); | |
ELSEIF op=2 THEN | |
RETURN CONCAT(num1,' - ',num2,' = ',num1-num2); | |
ELSEIF op=3 THEN |
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
DELIMITER // | |
CREATE PROCEDURE ProcSuma(IN nm1 INT, IN nm2 INT, OUT value INT) | |
BEGIN | |
SET value = nm1+nm2; | |
END; // | |
CREATE PROCEDURE ProcResta(IN nm1 INT, IN nm2 INT, OUT value INT) | |
BEGIN | |
SET value = nm1-nm2; |
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
#'\\' is a delimiter | |
select version() as 'mysql version'; | |
drop function if exists test; | |
create function test (opcion int,num1 int, num2 int) | |
returns int | |
BEGIN | |
declare res INT DEFAULT 0; | |
declare mensaje TEXT; | |
IF opcion=1 THEN |
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
DELIMITER $$ | |
CREATE PROCEDURE `my_proc_LOOP` (IN num INT) | |
BEGIN | |
DECLARE x INT; | |
SET x = 0; | |
loop_label: LOOP | |
INSERT INTO number VALUES (rand()); | |
SET x = x + 1; | |
IF x >= num | |
THEN |
NewerOlder