-
Notifications
You must be signed in to change notification settings - Fork 1
/
DBMSSQLServer.php
67 lines (60 loc) · 1.59 KB
/
DBMSSQLServer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require ("configuration.php");
/*
Classe genèrica per treballar amb una BD MS SQL Server
*/
class MSSQL{
public $conexion;
private $total_consultas;
function __construct(){
ini_set('mssql.charset', 'UTF-8');
if(!isset($this->conexion))
{ // Connect to MS SQL
$server = ICG_HOST;
$myDB = ICG_NAME;
$odbc="dblib:host=$server;dbname=$myDB";
$this->total_consultas = 0;
try {
$this->conexion = new PDO( $odbc , ICG_USER, ICG_PASSWORD);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}
}
public function getConexion(){
return $this->conexion;
}
public function consulta($consulta){
$this->total_consultas++;
$resultat = $this->conexion->prepare($consulta);
if($resultat->execute())
{
return $resultat;
} else {
//echo 'MSSQL Error: Consulta: '.$consulta."<br>";
return 0;
}
}
public function fetch_array($consulta){
$resultat = $this->conexion->prepare($consulta);
if($resultat->execute())
{
return $resultat->fetch(PDO::FETCH_ASSOC);
} else {
echo 'MSSQL Error: Consulta: '.$consulta."<br>";
return 0;
}
}
public function num_rows($consulta){
$result = $this->conexion->prepare($consulta);
$result->execute();
return $result->rowCount();
}
public function getTotalConsultas(){
return $this->total_consultas;
}
public function closeConnection(){
return $this->conexion->closeCursor();
}
}
?>