-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMetaDataDAO.php
52 lines (47 loc) · 1.29 KB
/
MetaDataDAO.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
<?php
namespace uzgent\VerifyClass;
/**
* Description of DataValue
*
* @author lveeckha
*/
class MetaDataDAO {
/**
* @var resource
*/
private $conn;
/**
*
* @param resource $conn
*/
public function __construct($conn)
{
if ($conn === null) throw new Exception("Connection cannot be null");
$this->conn = $conn;
}
/**
*
* @param int $projectid
* @param string $instrument_name
* @return string[]
*/
public function getFieldNames($projectid, $instrument)
{
$sql = "SELECT field_name FROM redcap_metadata WHERE project_id=? AND form_name=?";
$prepared = mysqli_prepare($this->conn, $sql);
mysqli_stmt_bind_param($prepared, "is", $projectid, $instrument);
mysqli_stmt_execute($prepared);
if (mysqli_stmt_error($prepared) != "")
{
throw new Exception("Unable to execute query " . mysqli_stmt_error($prepared) . " $sql");
}
$result = mysqli_stmt_get_result($prepared);
$queryResult = mysqli_fetch_assoc($result);
$names = [];
while ($queryResult !== null) {
$names[] = $queryResult["field_name"];
$queryResult = mysqli_fetch_assoc($result);
}
return $names;
}
}