This repository was archived by the owner on Apr 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdb.php
More file actions
171 lines (126 loc) · 5.31 KB
/
Copy pathdb.php
File metadata and controls
171 lines (126 loc) · 5.31 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/*
KEEP THIS CODE! THIS IS INCASE WE TURN THIS INTO A FULL ON BACKEND DB
AND NOT JUST FUNCTIONS TO COMMUNICATE WITH THE DB!!!
Original plan was to have a full on backend in php and then i realizwd
i didnt need it but will be helpful for the CORS proxy server!
$username= "vdenscfzdhznxf";
$password ="cc6bad208940188079d2533af5e46e724ba9ad0b06502f314c8b26a538a80a68";
$databasename="dbpdnfp0icj490";
$hostname= "ec2-52-202-22-140.compute-1.amazonaws.com";
$port="5432";
$connection = pg_connect("host=$hostname port=$port dbname=$databasename user=$username password=$password")
or die("could not connect");
if($connection->connect_error){
die("Connection failed: ".$connection->connect_error);
}
//table names in our heroku databse
//Pet- petID
//Users- userID
//petUserRel- petID, userID
*/
//Function to insert a pet into the DB
function petDBInsert($petid){
$username= "vdenscfzdhznxf";
$password ="cc6bad208940188079d2533af5e46e724ba9ad0b06502f314c8b26a538a80a68";
$databasename="dbpdnfp0icj490";
$hostname= "ec2-52-202-22-140.compute-1.amazonaws.com";
$port="5432";
$connect= pg_connect("host=$hostname port=$port dbname=$databasename user=$username password=$password")
or die("could not connect");
$sqlquery= "INSERT INTO public.'Pet'('petID') VALUES ($petid)";
if(pg_query($connect, $sqlquery)){
echo "new record created successfully";
}
else{
echo "Errror".pg_result_error($connect);
}
pg_close($connect);
}
//function to insert a user in our DB
function userDBInsert($userid){
$username= "vdenscfzdhznxf";
$password ="cc6bad208940188079d2533af5e46e724ba9ad0b06502f314c8b26a538a80a68";
$databasename="dbpdnfp0icj490";
$hostname= "ec2-52-202-22-140.compute-1.amazonaws.com";
$port="5432";
$connection = pg_connect("host=$hostname port=$port dbname=$databasename user=$username password=$password")
or die("could not connect");
$sqlquery= "INSERT INTO public.'Users'('userID') VALUES ($userid)";
if(pg_query($connection, $sqlquery)){
echo "new record created successfully";
}
else{
echo "Errror".pg_result_error($connection);
}
pg_close($connection);
}
//function to create a relationship within the user and saved pet :)
function petUserRelInsert($userid, $petid){
$username= "vdenscfzdhznxf";
$password ="cc6bad208940188079d2533af5e46e724ba9ad0b06502f314c8b26a538a80a68";
$databasename="dbpdnfp0icj490";
$hostname= "ec2-52-202-22-140.compute-1.amazonaws.com";
$port="5432";
$connection = pg_connect("host=$hostname port=$port dbname=$databasename user=$username password=$password")
or die("could not connect");
$sqlquery= "INSERT INTO public.'petUserRel'('userID', 'petID') VALUES ($userid, $petid)";
if(pg_query($connection, $sqlquery)){
echo "new record created successfully";
}
else{
echo "Errror".pg_result_error($connection);
}
pg_close($connection);
}
//get rows in saved pets to know how many react elements we will spawn
function getRowsInSavedPets(){
$username= "vdenscfzdhznxf";
$password ="cc6bad208940188079d2533af5e46e724ba9ad0b06502f314c8b26a538a80a68";
$databasename="dbpdnfp0icj490";
$hostname= "ec2-52-202-22-140.compute-1.amazonaws.com";
$port="5432";
$connection = pg_connect("host=$hostname port=$port dbname=$databasename user=$username password=$password")
or die("could not connect");
//$query= "SELECT petID FROM public.'petUserRel' WHERE userID= $userid ";
//query to only get pets for that specific user!
$query= "SELECT * FROM public.'Pet'";
$result=pg_query($connection,$query)
or die("Query error: " .pg_last_error());
$numrows = pg_num_rows($result);//how many cards we need to autogenerate!
return $numrows;
}
//return all saved pets in the DB for a user
function petDBQuery(){//once i get the userID working.. pass in $userid
$username= "vdenscfzdhznxf";
$password ="cc6bad208940188079d2533af5e46e724ba9ad0b06502f314c8b26a538a80a68";
$databasename="dbpdnfp0icj490";
$hostname= "ec2-52-202-22-140.compute-1.amazonaws.com";
$port="5432";
$connection = pg_connect("host=$hostname port=$port dbname=$databasename user=$username password=$password")
or die("could not connect");
//$query= "SELECT petID FROM public.'petUserRel' WHERE userID= $userid ";
//query to only get pets for that specific user!
$query= "SELECT * FROM public.'Pet'";
$result=pg_query($connection,$query)
or die("Query error: " .pg_last_error());
$numrows = pg_num_rows($result);//how many cards we need to autogenerate!
$numfields= pg_num_fields($result);// this is 1!
while($row = pg_fetch_row($result))
{
$i=0;
while($i < $numfields)
{
$current_value=$row[$i];
//the current value is the PETID!
//this value is what should be linked.
//Also i should have an API call to get me the picture.. ASkK TAYLOR IF I CAN STEAK
//HER CODE FOR IT
echo "".$current_value;
$i=$i+1;
}
pg_free_result($result);
};
pg_close($connection);
}
?>