<?php require_once 'classes/classe_bancodados.inc'; $bd = new mysql('localhost', 'root'); $bd->startTransaction(); $houveErro = false; $bd->executaSQL("use cake;"); $execRet = $bd->executaSQL("insert into articles(title, body) values ('aluno 01', 'Rafael Pomar');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("insert into articles(title, body) values ('aluno 02', 'Rafael garcia');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("insert into articles(title, body) values ('aluno 03', 'carlos');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("insert into articles(title, body) values ('aluno 04', 'Deise');"); if (!$execRet) { $houveErro = true; } if ($houveErro) { echo "houve um erro"; $bd->ROLLBACK(); } else { echo "sucesso, vamos gravar"; $bd->commit(); }
<?php require_once 'classes/classe_bancodados.inc'; //class BD extends BancoDados{}; $bd = new mysql('localhost', 'root'); //$conn = $bd->GetConn(); $articles = $bd->executaSQL("SELECT * FROM cake.articles"); //var_dump($articles); //die; $line = ''; while ($obj = $articles->fetch_object()) { $line .= $obj->id; $line .= $obj->title; $line .= $obj->body; $line .= "<br>"; } echo $line;
<?php require_once 'classes/classe_bancodados.inc'; $bd = new mysql('localhost', 'root'); $articles = $bd->executaSQL("select * from cake.articles"); $line = ''; while ($obj = $articles->fetch_object()) { $line .= $obj->id; $line .= $obj->title; $line .= $obj->body; $line .= "<br>"; } echo $line; ?>
<?php require_once 'classes/classe_bancodados.inc'; $bd = new mysql('localhost', 'root'); $bd->startTransaction(); $houveErro = false; $bd->executaSQL("use cake;"); $execRet = $bd->executaSQL("insert into articles(title, body) values ('aluno 05', 'Rafael atrasado');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("insert into articles(title, body) values ('aluno 06', 'Rafael sr.net');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("insert into articles(title, body) values ('aluno 07', 'Carlos faster');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("insert into articles(title, body) values ('aluno 08', 'Deise loka');"); if (!$execRet) { $houveErro = true; } if ($houveErro) { echo "Erro!"; $bd->ROLLBACK(); } else { echo "Tudo OK!"; $bd->commit(); } // echo $sql;
<?php require_once 'classes/classe_bancodados.inc'; $bd = new mysql('localhost', 'root'); $bd->startTransaction(); $houveErro = false; $bd->executaSQL("use cake;"); $execRet = $bd->executaSQL("INSERT INTO articles (title, body) VALUES ('Aluno 01', 'Rafael Pomar');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("INSERT INTO articles (title, body) VALUES ('Aluno 02', 'Carlos');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("INSERT INTO articles (title, body) VALUES ('Aluno 03', 'Rafael Garcia');"); if (!$execRet) { $houveErro = true; } $execRet = $bd->executaSQL("INSERT INTO articles (title, body) VALUES ('Aluno 04', 'Deise');"); if (!$execRet) { $houveErro = true; } if ($houveErro) { $bd->ROLLBACK(); } else { $bd->commit(); }