-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_transaction.php
74 lines (69 loc) · 1.89 KB
/
insert_transaction.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
68
69
70
71
72
73
74
<?php
session_start();
$gameid=$_REQUEST["gameid"];
$curr1=$_REQUEST["curr1"];
$curr2=$_REQUEST["curr2"];
$sum=$_REQUEST["sum"];
try{
//create new transaction id
$conn=oci_connect('speculapp','SPECULAPP','localhost/XE');
if (!$conn) {
$e = oci_error();
throw new Exception;
}
// Prepare the statement
$stid = oci_parse($conn, 'SELECT MAX(TRANSACTION_ID) FROM TRANSACTION');
if (!$stid) {
$e = oci_error($conn);
throw new Exception;
}
// Perform the logic of the query
$r = oci_execute($stid);
if (!$r) {
$e = oci_error($stid);
throw new Exception;
}
$row=oci_fetch_array($stid, OCI_NUM);
$oldtransactionid=$row[0];
$transactionid=$oldtransactionid+1;
oci_free_statement($stid);
//fetch currency IDes
$stid=oci_parse($conn,'SELECT CURR_ID FROM CURRENCY WHERE TRIGRAMM=:curr');
if(!$stid){
throw new Exception;
}
oci_bind_by_name($stid,':curr',$curr1);
$r=oci_execute($stid);
if(!$r){
throw new Exception;
}
$row=oci_fetch_array($stid, OCI_NUM);
$currid1=$row[0];
oci_bind_by_name($stid,':curr',$curr2);
$r=oci_execute($stid);
if(!$r){
throw new Exception;
}
$row=oci_fetch_array($stid,OCI_NUM);
$currid2=$row[0];
oci_free_statement($stid);
$stid=oci_parse($conn,'INSERT INTO TRANSACTION VALUES(:transactionid,:sessionid,:gameid,:userid,:curr1,:curr2,:sum1,:sum2,sysdate)');
if(!$stid){
throw new Exception;
}
oci_bind_by_name($stid,':transactionid',$transactionid);
oci_bind_by_name($stid,':sessionid',$_SESSION["sesion"]);
oci_bind_by_name($stid,':gameid',$gameid);
oci_bind_by_name($stid,':userid',$_SESSION["uid"]);
oci_bind_by_name($stid,':curr1',$currid1);
oci_bind_by_name($stid,':curr2',$currid2);
oci_bind_by_name($stid,':sum1',$sum);
oci_bind_by_name($stid,':sum2',$sum);
$r=oci_execute($stid);
if(!$r){
throw new Exception;
}
oci_free_statement($stid);
}catch(Exception $e){
}
?>