Exemple #1
0
 /**
  * Returns a PDO instance -- a connection to the database.
  * The singleton instance assures that there is only one connection active
  * at once (within the scope of one HTTP request)
  *
  * @return PDO instance
  */
 public static function getInstance()
 {
     if (!self::$instance) {
         $config = "mysql:host=" . self::$host . ";dbname=" . self::$schema;
         $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
         self::$instance = new PDO($config, self::$user, self::$password, $options);
     }
     return self::$instance;
 }
 function __construct()
 {
     parent::__construct();
     $this->createtableTurma();
 }
<?php

require_once "../conection.php";
$conex = new conection();
$result = $conex->conex();
$id = $_GET['id'];
$query = mysqli_query($result, "delete from contactos where id='{$id}'");
?>

<html>
	<head>
		<title>Contactos</title>
		<meta charset="UTF-8" />
		<link rel='stylesheet' href='../css/reset.css' />
		<link rel='stylesheet' href='../css/estilos.css' />
	</head>
	
	<body>
		<center>
			<?php 
if ($query > 0) {
    ?>
				
				<h1>Contacto Eliminado</h1>
				
				<?php 
} else {
    ?>
				
				<h1>Error al Eliminar Contacto</h1>
				
Exemple #4
0
 public static function sklenitvezvez2015($min, $max)
 {
     $db = conection::getInstance();
     $db->exec("set names utf8");
     $query = "SELECT * FROM celotna WHERE `skupno2015` > :min AND `skupno2015`<:max ORDER BY `sklenitvezvez2015` DESC ";
     $stmt = $db->prepare($query);
     $stmt->bindParam(":min", $min);
     $stmt->bindParam(":max", $max);
     $stmt->execute();
     $result = $stmt->fetchAll();
     $rows = array();
     foreach ($result as $row) {
         $rows[] = $row;
     }
     echo json_encode($rows);
 }
<?php

class conection
{
    function conex()
    {
        $dbserver = "52.25.205.86:3306";
        // $dbserver = "127.0.0.1";
        // $dbserver = "localhost";
        $dbuser = "******";
        $password = "******";
        // $password = "";
        $dbname = "cocorrico";
        $conex = new mysqli($dbserver, $dbuser, $password, $dbname);
        if ($conex->connect_errno) {
            echo "Errno: " . $conex->connect_errno . "\n";
            echo "Error: " . $conex->connect_error . "\n";
            die("No se pudo conectar a la base de datos");
        }
        return $conex;
    }
}
$conn = new conection();
$conn->conex();
 function __construct()
 {
     parent::__construct();
     $this->createtableAluno();
 }