diff --git a/DBConn.php b/DBConn.php
new file mode 100644
index 000000000..fc07fda42
--- /dev/null
+++ b/DBConn.php
@@ -0,0 +1,281 @@
+connectToDatabase();
+ }
+
+ function connectToDatabase()
+ {
+ $dsn = "mysql:dbname=db;host=localhost";
+ $user = "root";
+ $password = "";
+ try{
+ $this->conn = new PDO($dsn, $user, $password);
+ }
+ catch(Exception $e)
+ {
+ $this->errors[] = $e->getMessage();
+ return false;
+ }
+ return true;
+ }
+
+ function close()
+ {
+ $this->conn = NULL;
+ }
+
+ function rowCount()
+ {
+ return $this->numRows;
+ }
+
+ function update($query, $newValues = array(), $whereValues = array())
+ { //echo "update function parameters passed in
newValues: ".print_r($newValues, true)."
whereValues: ".print_r($whereValues, true)."";
+ $this->numRows = 0;
+ $this->errors = array();
+ if(!is_array($newValues))
+ {
+ $newValues = (array)$newValues;
+ }
+ if(!is_array($whereValues))
+ {
+ $whereValues = (array)$whereValues;
+ }
+ $newValues = $this->clean($newValues);
+ $whereValues = $this->clean($whereValues);
+ try{
+ //echo "preparing update
";
+ if (($stmt = $this->conn->prepare($query)) === false)
+ {
+ $this->errors[] = "Error preparing update query: ".$query.PHP_EOL."Values: ".print_r($newValues, true).print_r($whereValues, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ $count = 1;
+ if (count($newValues)>0)
+ {//echo "new values count > 0.
";
+ foreach($newValues as $key=>&$value)
+ {
+ //echo "binding value: $value
";
+ if(($stmt->bindParam($count, $value)) === false)
+ {
+ $this->errors[] = "Error binding 'new' parameters for update statement: ".$query.PHP_EOL."Values: ".print_r($newValues, true).print_r($whereValues, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ $count++;
+ }
+ }
+ if (count($whereValues)>0)
+ {//echo "where values count > 0.
";
+ foreach($whereValues as $key=>&$value)
+ {//echo "binding value: $value
";
+ if(($stmt->bindParam($count, $value)) === false)
+ {
+ $this->errors[] = "Error binding 'where' parameters for update statement: ".$query.PHP_EOL."Values: ".print_r($newValues, true).print_r($whereValues, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ $count++;
+ }
+ }
+ if (($stmt->execute()) === false)
+ {
+ $this->errors[] = "Error executing update statement: ".$query.PHP_EOL."Values: ".print_r($newValues, true).print_r($whereValues, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ //echo "statement executed
";
+ }
+ catch(Exception $e)
+ {
+ $this->errors[] = $e->getMessage();
+ return false;
+ }
+ $this->numRows = $stmt->rowCount();
+ //echo "update statement should have been successful
";
+ return true;
+ }
+
+ function insert($query, $values = array())
+ {
+ $this->numRows = 0;
+ $this->errors = array();
+ if(!is_array($values))
+ {
+ $values = (array)$values;
+ }
+ $values = $this->clean($values);
+ try{
+ if (($stmt = $this->conn->prepare($query)) === false)
+ {
+ $this->errors[] = "Error preparing insert query: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ if (count($values)>0)
+ {
+ foreach($values as $key=>&$value)
+ {
+ if(($stmt->bindParam($key + 1, $value)) === false)
+ {
+ $this->errors[] = "Error binding parameters for insert statement: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ }
+ }
+ if (($stmt->execute()) === false)
+ {
+ $this->errors[] = "Error executing insert statement: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ }
+ catch(Exception $e)
+ {
+ $this->errors[] = $e->getMessage();
+ return false;
+ }
+ $this->numRows = $stmt->rowCount();
+ return true;
+ }
+
+
+ function select($query, $values = array())
+ {
+ $this->numRows = 0;
+ $this->errors = array();
+ if(!is_array($values))
+ {
+ $values = (array)$values;
+ }
+ $values = $this->clean($values);
+ try{
+ if (($stmt = $this->conn->prepare($query)) === false)
+ {
+ $this->errors[] = "Error preparing select query: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ if(count($values)>0)
+ {
+ foreach($values as $key=>&$value)
+ {
+ if(($stmt->bindParam($key + 1, $value)) === false)
+ {
+ $this->errors[] = "Error binding parameters for select statement: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ }
+ }
+ if (($stmt->execute()) === false)
+ {
+ $this->errors[] = "Error executing select statement: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ if (($rows = $stmt->fetchAll(PDO::FETCH_ASSOC)) === false)
+ {
+ $this->errors[] = "Error fetching rows for query: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ }
+ catch(Exception $e)
+ {
+ $this->errors[] = $e->getMessage();
+ return false;
+ }
+ $this->numRows = count($rows);
+ return $rows;
+ }
+
+ function delete($query, $values = array())
+ {
+ $this->numRows = 0;
+ $this->errors = array();
+ if(!is_array($values))
+ {
+ $values = (array)$values;
+ }
+ $values = $this->clean($values);
+ try{
+ if (($stmt = $this->conn->prepare($query)) === false)
+ {
+ $this->errors[] = "Error preparing delete query: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ if (count($values)>0)
+ {
+ foreach($values as $key=>&$value)
+ {
+ if(($stmt->bindParam($key + 1, $value)) === false)
+ {
+ $this->errors[] = "Error binding parameters for delete statement: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ }
+ }
+ if (($stmt->execute()) === false)
+ {
+ $this->errors[] = "Error executing delete statement: ".$query.PHP_EOL."Values: ".print_r($values, true);
+ $messageArray = $stmt->errorInfo();
+ $this->errors[] = $messageArray[2];
+ return false;
+ }
+ }
+ catch(Exception $e)
+ {
+ $this->errors[] = $e->getMessage();
+ return false;
+ }
+ $this->numRows = $stmt->rowCount();
+ return true;
+ }
+
+ function getErrors()
+ {
+ return $this->errors;
+ }
+
+ function clean($values = array())
+ {//echo "in clean, values passed in:
".print_r($values, true)."
| Username | +Active User? | +Admin User? | +Activate/Deactivate | +Admin Control | +Reset Password | + + + +
|---|---|---|---|---|---|
| + | + | + | + | + | Reset Password |
+
Hello World!
- -<<<<<<< HEAD -Search bar
->>>>>>> jvbkw8 - - diff --git a/index.php b/index.php new file mode 100644 index 000000000..6337051c5 --- /dev/null +++ b/index.php @@ -0,0 +1,26 @@ + + + +The goal of this application is to facilitate the research of computational social scientists and data scientists alike by serving as a repository for datasets and metadata following the Open Community Data eXchange (OCDX) specification.
++ View the OCDX specification on their Github page. +
+| Test Passed | +Login Success | +Expected Success? | +Username | +Password | +Admin? | +DB Errors | + + + +
|---|
| File Name | +Owner | +Get File | +View Manifest | +Manifest Name | +Delete File? | +|
|---|---|---|---|---|---|---|
| + | + | Download | ++ | + + | + + | You Are Not The Owner | + +