function deleteCliente($codigo) { $sql = "DELETE FROM cliente WHERE codigo=:codigo"; $conn = getConn(); $stmt = $conn->prepare($sql); $stmt->bindParam("codigo", $codigo); $stmt->execute(); }
function printMyRecipes() { $conn = getConn(); $userid = $_SESSION["userid"]; $sql = " SELECT * FROM recipe\n\t\t\t\tWHERE author = '{$userid}'"; $result = $conn->query($sql); printResultWithX($result); }
function printMyCookbooks() { $userid = $_SESSION["userid"]; $conn = getConn(); $sql = " SELECT * FROM cookbook \n\t\t\t\tWHERE cookbook_id in (\n\t\t\t\t\tSELECT cookbook_id FROM cookbook_list\n\t\t\t\t\tWHERE user_id = '{$userid}')"; $result = $conn->query($sql); printResultWithX($result); }
function getProdutos() { $sql = "SELECT *,Categorias.nome as nomeCategoria FROM Produtos,Categorias WHERE Categorias.id=Produtos.idCategoria"; $stmt = getConn()->query($sql); $produtos = $stmt->fetchAll(PDO::FETCH_OBJ); echo json_encode($produtos); exit; echo "{\"produtos\":" . json_encode($produtos) . "}"; }
function listScores() { $conn = getConn(); $res = $conn->query("select * from messages where message <> '' and not(message is null) order by creation_date desc"); if (!$res) { echo $conn->error; $conn->close(); exit; } return $res; }
function getFieldNameList($db_name, $table_name) { $fieldNames = array(); $sql_str = "desc `{$table_name}`"; $conn = getConn(); mysql_select_db($db_name, $conn); $result = mysql_query($sql_str, $conn); while ($row = mysql_fetch_row($result)) { array_push($fieldNames, array($row[0], $row[1])); } mysql_free_result($result); return $fieldNames; }
function getHAMSElementID($blismeasureid) { $conn = getConn(); $recordSet =& $conn->Execute("select HAMSID from TEST_ELEMENTS_MAPPING where BLISID =" . $blismeasureid); if (!$recordSet) { return NULL; } else { if (!$recordSet->EOF) { return $recordSet->fields[0]; } else { return 0; } } }
function doUpdate($sql) { global $debugdb; if ($debugdb) { logMessage('db', 3, "SQL - " . $sql); } $conn = getConn(); $result = $conn->query($sql); if (DB::isError($result)) { logMessage('db', 0, "Query Error " . $result->getMessage(), null, null); genPipeError('db'); } return $conn->affectedrows(); }
function __construct($id = NULL, $email = NULL, $fname = NULL, $lname = NULL, $fbtoken = NULL) { $this->id = $id; $this->email = $email; $this->fname = $fname; $this->lname = $lname; $this->fbtoken = $fbtoken; $DBH = getConn(); $SMT = $DBH->prepare("INSERT INTO users (id, email, fname, lname, fbtoken) VALUES (:id, :email, :fname, :lname, :fbtoken)"); $SMT->bindParam(':id', $id); $SMT->bindParam(':email', $email); $SMT->bindParam(':fname', $fname); $SMT->bindParam(':lname', $lname); $SMT->bindParam(':fbtoken', $fbtoken); $SMT->execute(); }
function isOwner($cookbook_id) { $conn = getConn(); $user_id = $_SESSION['userid']; $sql = "SELECT user_id FROM Cookbook_list WHERE user_id = '{$user_id}' AND cookbook_id ='{$cookbook_id}'"; if ($conn->query($sql) != true) { //unsuccessful query header('Location: fail.php'); } $result = $conn->query($sql); $row = $result->fetch_assoc(); if (count($row) == 1) { return true; } else { return false; } }
function search($origin, $destination, $date) { $origin = strtolower($origin); $destination = strtolower($destination); $date = date('Y-m-d', strtotime($date)); $DBH = getConn(); $SMT = $DBH->prepare("SELECT * FROM posts WHERE origin=:origin AND destination=:destination AND ridedate=:date"); $SMT->bindValue(":origin", $origin); $SMT->bindValue(":destination", $destination); $SMT->bindValue(":date", $date); $results = array(); if ($SMT->execute()) { $results = $SMT->fetchAll(PDO::FETCH_CLASS, "Post"); } if (count($results) == 0) { return false; } return $results; }
function recuperarListaTabelas() { assert(getConn()); $q = mysql_query("SHOW TABLES", getConn()); $tabelas = array(); while ($row = mysql_fetch_row($q)) { $tabelas[$row[0]] = array(); } foreach (array_keys($tabelas) as $tabela) { $q2 = mysql_query("DESCRIBE `{$tabela}`;", getConn()); $tabelas[$tabela]['campos'] = array(); while ($row2 = mysql_fetch_row($q2)) { $tabelas[$tabela]['nome'] = $tabela; $tabelas[$tabela]['campos'][$row2[0]] = array($row2[1], $row2[3], $row2[5], $row2[2]); if ($row2[3] == "PRI") { $tabelas[$tabela]['chave'] = array($row2[0], $row2[1], $row2[3], $row2[5], $row2[2]); } } } return $tabelas; }
private static function Select($login, $pass = null) { $conn = getConn(); $q = 'Select id, name, surname, isAdmin From Users Where login=?'; if (isset($pass)) { $q .= ' And password=md5(?)'; } $stmt = $conn->prepare($q); if (isset($pass)) { $stmt->bind_param('ss', $login, $pass); } else { $stmt->bind_param('s', $login); } if ($stmt->execute() && ($res = $stmt->get_result()) && ($row = $res->fetch_row())) { $user = new User(); $user->id = $row[0]; $user->name = $row[1]; $user->surname = $row[2]; $user->isAdmin = $row[3]; $user->login = $login; return $user; } return null; }
function __construct($owner = NULL, $ridedate = NULL, $ridetime = NULL, $origin = NULL, $destination = NULL, $description = NULL, $email = NULL, $phone = NULL, $type = NULL) { $this->owner = $owner; $this->ridedate = $ridedate; $this->origin = $origin; $this->destination = $destination; $this->description = $description; $this->email = $email; $this->phone = $phone; $this->type = $type; $DBH = getConn(); $SMT = $DBH->prepare("INSERT INTO posts (owner, ridedate, ridetime, origin, destination, description, email, phone, type) VALUES (:owner, :ridedate, :ridetime, :origin, :destination, :description, :email, :phone, :type)"); $SMT->bindParam(':owner', $owner); $SMT->bindParam(':ridedate', $ridedate); $SMT->bindParam(':ridetime', $ridetime); $SMT->bindParam(':origin', $origin); $SMT->bindParam(':destination', $destination); $SMT->bindParam(':description', $description); $SMT->bindParam(':email', $email); $SMT->bindParam(':phone', $phone); $SMT->bindParam(':type', $type); $SMT->execute(); $DBH = null; }
function getEm() { $em = EntityManager::create(getConn(), getConfig()); return $em; }
<?php include "config.php"; ?> <html> <body> <?php if (getConn()) { $tabelas = recuperarListaTabelas(); ?> <form method="post" name="gerar"> <table> <tr><td>Marcar</td><td>Tabela</td><td>Nome da Classe</td></tr> <?php foreach (array_keys($tabelas) as $nometabela) { ?> <tr> <td><input checked type="checkbox" name="tabelas_requeridas[]" value="<?php echo $nometabela; ?> "/></td> <td><?php echo $nometabela; ?> </td> <td><input type="text" name="classe_<?php echo $nometabela; ?>
$status = array('status' => 'success'); $status = json_encode($status); } catch (Exception $e) { $db->rollBack(); $status = array('status' => 'Error'); $status = json_encode($status); } } unset($db); $db = null; echo $status; }); $app->post('/enviafotos', 'authenticate', function () use($app) { $request = \Slim\Slim::getInstance()->request(); $requisicao = json_decode($request->getBody()); $db = getConn(); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $status = "Erro de insert"; foreach ($requisicao as $objeto) { $OS = $objeto->{'id_os'}; $ID_LOCAL = $objeto->{'id_local'}; $FOTO = $objeto->{'foto'}; $FOTO_DECODE = base64_decode($FOTO); $caminhofoto = '../../imagens/fotos/' . $OS . '/' . $ID_LOCAL . '/'; if (!is_dir($caminhofoto)) { mkdir($caminhofoto, 0777, true); } if (is_dir($caminhofoto)) { //se existir a pasta $arquivos = glob("{$caminhofoto}{*.jpg,*.JPG,*.png,*.gif,*.bmp}", GLOB_BRACE); //conta se ja existe arquivo na pasta
public function __construct() { $this->view = new View(); $this->conn = getConn(); }
<?php //pegaPontos(); //<<<<<<<<<<<<<<<<<< AGENCIA >>>>>>>>>>>>>>>>>>>>>>>> //function pegaPontos() { //$request = \Slim\Slim::getInstance()->request(); //$produto = json_decode($request->getBody()); //$agencia = $request->getBody(); //$sql = "INSERT INTO agencia (nome,cnpj,id) values (:nome,:cnpj,:id) "; $stmt = getConn()->query("select * from dados d join app_lista al on d.dados=al.id where resolvido=0"); $pontos = $stmt->fetchAll(PDO::FETCH_OBJ); // echo "{pontos:" . json_encode($pontos) . "}"; // Cria o arquivo se ele não existir // Escreve 'Michel Fernandes' ao final do arquivo //$arquivo = fopen('json.txt','a+'); //if ($arquivo) { // // move o ponteiro para o inicio do arquivo // rewind($arquivo); // if (!fwrite($arquivo, json_encode($pontos))) die('Não foi possível atualizar o arquivo.'); // echo 'Arquivo atualizado com sucesso'; // fclose($arquivo); //} // Sobre escreve o arquivo partindo do começo //delete('json.txt'); // CÓDIGO ABAIXO CRIA UM ARQUIVO EM BRANCO $arquivo = fopen('web/js/pontos.json', 'w+'); if ($arquivo == false) { unlink('web/js/pontos.json'); } $arquivo = fopen('web/js/pontos.json', 'r+'); if ($arquivo) {
/** * Method update * * Altera o valor de registro em uma * tabela do banco de dado * * @param array * @param array * @return integer */ public function update($param, $data) { if (empty($this->getTable())) { throw new \RuntimeException('Nome da tabela não definido.'); return; } if (count($param) == 0 or count($data) == 0) { throw new \InvalidArgumentException('Valores inválidos para [param] ou [data].'); return; } $keys = implode('=?, ', array_keys($data)) . '=?'; $conds = implode('=?, ', array_keys($param)) . '=?'; $sql = sprintf('UPDATE %s SET %s WHERE %s', $this->getTable(), $keys, $conds); $stmt = $this - getConn()->prepare($sql); $i = 1; $values = array_merge($data, $param); foreach ($values as $v) { $stmt->bindValue($i++, $v, self::getTypePDO($v)); } if (!$stmt->execute()) { throw new \RuntimeException('Erro ao apagar dados na table ' . $this->getTable()); return null; } }
/** * @author Simone Romano * Validate user registration **/ function checkValidation($email, $name) { $conn = getConn(); $validationCode = md5($email . $name); $now = (new \DateTime())->format('Y-m-d H:i:s'); $sql = "select validationCode from utente where email='{$email}'"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $validationCodeInDb = $row['validationCode']; echo "{$validationCode} {$validationCodeInDb}"; if ($validationCode == $validationCodeInDb) { return true; } else { return false; } } } return false; mysqli_close($conn); }
<?php /* All */ require "inc/config.php"; $stmt = getConn()->query("SELECT * FROM photos"); $photos = $stmt->fetchAll(PDO::FETCH_OBJ); echo json_encode($photos);
<?php require_once 'base.php'; $userID = isset($_POST['id']) ? $_POST['id'] : NULL; $userEmail = isset($_POST['email']) ? $_POST['email'] : NULL; $userName = isset($_POST['name']) ? $_POST['name'] : NULL; $userPhone = isset($_POST['phone']) ? $_POST['phone'] : NULL; $DBH = getConn(); $SMT = $DBH->query("SELECT * FROM users WHERE id = '{$userID}'"); //$SMT->bindValue(":origin", $origin); //$SMT->bindValue(":destination", $destination); //$SMT->bindValue(":date", $date); $results = array(); if ($SMT) { $results = $SMT->fetchAll(); if (count($results) == 0) { $SMT = $DBH->query("INSERT INTO users (id, name, email) VALUES ('{$userID}', '{$userName}', '{$userEmail}')"); } else { return true; } }
function getConn($db) { global $db_user, $db_pwd; $conn = mysql_connect('ai-imci-control01.ai01.baidu.com:8908', $db_user, $db_pwd, true); mysql_query('SET NAMES UTF-8', $conn); mysql_select_db($db, $conn); return $conn; } //TRUNCATE TABLE echo 'This operation will erease all data in table:servers, tags, servers_tags!Are you sure?(y/N):'; $confirm = read(); if ($confirm != 'Y' && $confirm != 'y') { exit; } $conn = getConn($db); $conn_old = getConn($old_db); mysql_query("TRUNCATE TABLE `servers`", $conn); mysql_query("TRUNCATE TABLE `tags`", $conn); mysql_query("TRUNCATE TABLE `servers_tags`", $conn); //Insert tags echo "[1mClone tags[0m\n"; $tag_res = mysql_query('SELECT DISTINCT `name`,`description` FROM `tags`', $conn_old); $tag_insert_sql = "INSERT INTO `tags` (`tag_segment_id`, `name`, `description`) VALUES "; $tag_insert_sql .= "(6, 'im', NULL),(6, 'shifen', NULL),"; //产品线tag处理。 while ($tag = mysql_fetch_assoc($tag_res)) { echo "\t{$tag['name']}:"; $tag['description'] = str_replace("'", '"', $tag['description']); $tag_segment = 'other'; foreach ($segment as $seg) { if (in_array($tag['name'], ${$seg})) {
function getUserByID($id) { $DBH = getConn(); $SMT = $DBH->query("SELECT * FROM users WHERE id = {$id} "); if ($SMT->execute()) { $result = $SMT->fetchAll(); } return $result[0]; }
<?php //pegaPontos(); //<<<<<<<<<<<<<<<<<< AGENCIA >>>>>>>>>>>>>>>>>>>>>>>> //function pegaPontos() { //$request = \Slim\Slim::getInstance()->request(); //$produto = json_decode($request->getBody()); //$agencia = $request->getBody(); //$sql = "INSERT INTO agencia (nome,cnpj,id) values (:nome,:cnpj,:id) "; echo "Entrou"; $stmt = getConn()->query("SELECT * FROM DADOS D JOIN APP_LISTA AL ON D.DADOS =AL.ID WHERE RESOLVIDO=0"); $pontos = $stmt->fetchAll(PDO::FETCH_OBJ); // echo "{pontos:" . json_encode($pontos) . "}"; // Cria o arquivo se ele não existir // Escreve 'Michel Fernandes' ao final do arquivo //$arquivo = fopen('json.txt','a+'); //if ($arquivo) { // // move o ponteiro para o inicio do arquivo // rewind($arquivo); // if (!fwrite($arquivo, json_encode($pontos))) die('Não foi possível atualizar o arquivo.'); // echo 'Arquivo atualizado com sucesso'; // fclose($arquivo); //} // Sobre escreve o arquivo partindo do começo //delete('json.txt'); // CÓDIGO ABAIXO CRIA UM ARQUIVO EM BRANCO $arquivo = fopen('pontos.json', 'w+'); if ($arquivo == false) { unlink('pontos.json'); } $arquivo = fopen('pontos.json', 'r+');
<?php /* Query by ID */ require "inc/config.php"; if (isset($_GET["id"])) { $id = $_GET["id"]; $stmt = getConn()->query("SELECT * FROM photos WHERE id='{$id}'"); $photos = $stmt->fetchAll(PDO::FETCH_OBJ); $response["status"] = "success"; $response["photos"] = $photos; echo json_encode($response); } else { $response["error"] = "error"; $response["message"] = "Foto não encontrada"; echo json_encode($response); }
return !empty($this->data) ? $this->dst : $this->src; } public function getMsg() { return $this->msg; } } $crop = new CropAvatar(isset($_POST['avatar_src']) ? $_POST['avatar_src'] : null, isset($_POST['avatar_data']) ? $_POST['avatar_data'] : null, isset($_FILES['avatar_file']) ? $_FILES['avatar_file'] : null); /* $response = array( 'state' => 200, 'message' => $crop -> getMsg(), 'result' => $crop -> getResult() ); */ $sql = "INSERT INTO photos (name_file) values (:name_file)"; $conn = getConn(); $stmt = $conn->prepare($sql); $stmt->bindParam("name_file", $crop->getResult()); $stmt->execute(); $id = $conn->lastInsertId(); if ($id != NULL) { $response["state"] = 200; $response["status"] = "success"; $response["message"] = "Foto adicionada"; $response["result"] = $id; } else { $response["status"] = "error"; $response["message"] = "Erro ao adicionar a foto"; } echo json_encode($response);
function isFriend($cookbook_id) { $conn = getConn(); $userid = $_SESSION["userid"]; $sql = " SELECT * FROM account\n\t\t\t\tWHERE user_id = '{$userid}'\n\t\t\t\t\tAND email in (\n\t\t\t\t\t\tSELECT email FROM friends \n\t\t\t\t\t\tWHERE type = 'COOKBOOK' \n\t\t\t\t\t\t\tAND type_id = '{$cookbook_id}')"; $result = $conn->query($sql); return $result->num_rows > 0; }
//$agencia = $request->getBody(); //$sql = "INSERT INTO agencia (nome,cnpj,id) values (:nome,:cnpj,:id) "; // echo "{pontos:" . json_encode($pontos) . "}"; // Cria o arquivo se ele não existir // Escreve 'Michel Fernandes' ao final do arquivo //$arquivo = fopen('json.txt','a+'); //if ($arquivo) { // // move o ponteiro para o inicio do arquivo // rewind($arquivo); // if (!fwrite($arquivo, json_encode($pontos))) die('Não foi possível atualizar o arquivo.'); // echo 'Arquivo atualizado com sucesso'; // fclose($arquivo); //} // Sobre escreve o arquivo partindo do começo //delete('json.txt'); $stmt = getConn()->query("select d.id,latitude,longitude,dados,valor,icone from dados d join app_lista al on d.dados=al.id where resolvido=0"); $pontos = $stmt->fetchAll(PDO::FETCH_OBJ); // CÓDIGO ABAIXO CRIA UM ARQUIVO EM BRANCO $arquivo = fopen('web/js/pontos.json', 'w+'); if ($arquivo == false) { unlink('web/js/pontos.json'); } $arquivo = fopen('web/js/pontos.json', 'r+'); if ($arquivo) { if (!fwrite($arquivo, str_replace("\\/", "/", json_encode($pontos)))) { die('Não foi possível atualizar o arquivo.'); } echo "Obtendo pontos..."; echo '<meta http-equiv="refresh" content="2; url=http://localhost:8080/Dengue/index.jsp">'; fclose($arquivo); }