-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectionFactory.php
executable file
·57 lines (50 loc) · 1.97 KB
/
connectionFactory.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
<?php
class ConnectionFactory {
public static function GetConnection() {
date_default_timezone_set("UTC");
$mysqli = new mysqli("myMysqlHostnameOrIpWithOptionalPort","myDbUser","myDbPassword","myDbName");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli->connect_error;
}
if (!$mysqli->set_charset("utf8")) {
printf("Erreur lors du chargement du jeu de caractères utf8 : %s\n", $mysqli->error);
}
return $mysqli;
}
}
function validMember($mysqli, $Code) {
$stmt = $mysqli->prepare("
SELECT
Reg_Code.PersonId,
Reg_Code.Currency,
RecordTypeId,
Reg_Legal.Name,
Reg_Legal.Contact,
Reg_Legal.ContactSurname,
Reg_Individual.FirstName,
Reg_Individual.LastName,
Code
FROM Reg_Code
INNER JOIN Reg_Person ON Reg_Person.Id=Reg_Code.PersonId
LEFT OUTER JOIN Reg_Legal ON Reg_Person.Id = Reg_Legal.Id
LEFT OUTER JOIN Reg_Individual ON Reg_Person.Id = Reg_Individual.Id
WHERE Code=?");
$stmt->bind_param("s", $Code);
$stmt->bind_result($id, $currency, $type,$company,$ct_name, $ct_surname,$surname,$lastname,$res_code);
$stmt->execute();
$result = array( "Valid"=>False);
while ($stmt->fetch()){
if ($type == 1) {
$person = $ct_surname." ".$ct_name;
$first = $ct_surname;
$last = $ct_name;
} else {
$person = $surname." ".$lastname;
$first = $surname;
$last = $lastname;
}
$result = array("id"=>$id,"code"=>$res_code, "Curr"=>$currency, "Valid"=>($res_code==$Code), "Name"=>$person, "FirstName"=>$first, "LastName"=>$last, "Company"=>$company, "Type"=>$type);
}
return $result;
}
?>