db.php
Go to the documentation of this file.
00001 <?php 00002 00005 00026 class DB_Virtuoso 00027 { 00029 private $db_host; 00030 00032 private $db_user; 00033 00035 private $db_pass; 00036 00038 private $dsn; 00039 00041 private $resultset; 00042 00044 private $db_link; 00045 00047 private $queryProcessTime = 0; // In milliseconds 00048 00062 public function DB_Virtuoso($username, $password, $dsn, $host) 00063 { 00064 // Connection Database informations 00065 $this->db_host = $host; 00066 $this->db_user = $username; 00067 $this->db_pass = $password; 00068 $this->dsn = $dsn; 00069 00070 $this->connect(); 00071 } 00072 00081 private function connect() 00082 { 00083 $this->db_link = odbc_connect($this->dsn, $this->db_user, $this->db_pass, SQL_CUR_USE_ODBC); 00084 00085 // odbc_binmode(0, 1); 00086 // odbc_longreadlen(0, 65534); 00087 00088 // ini_set("odbc.defaultlrl", "65534"); 00089 00090 return; 00091 } 00092 00093 public function getError() { return (odbc_error($this->db_link)); } 00094 00095 public function getErrorMsg() { return (odbc_errormsg($this->db_link)); } 00096 00110 public function query($db_query, $benchmark = FALSE) 00111 { 00112 if(isset($_GET['benchmark']) && $_GET['benchmark'] == 1) 00113 { 00114 // Start TIMER 00115 // ----------- 00116 $stimer = explode(' ', microtime()); 00117 $stimer = $stimer[1] + $stimer[0]; 00118 // ----------- 00119 00120 $resultset = odbc_exec($this->db_link, $db_query); 00121 00122 // End TIMER 00123 // --------- 00124 $etimer = explode(' ', microtime()); 00125 $etimer = $etimer[1] + $etimer[0]; 00126 // --------- 00127 00128 $this->queryProcessTime = (($etimer - $stimer) * 1000); 00129 00130 echo "<div>"; 00131 00132 echo "Sparql query: <em>" . str_replace(array ("<", ">"), array ("<", ">"), $db_query) . "</em><br>"; 00133 00134 echo "Execution time: " . $this->queryProcessTime . " milliseconds<br><br>\n"; 00135 00136 echo "</div>"; 00137 } 00138 00139 if((isset($_GET['debug']) && $_GET['debug'] == 2) || $benchmark === TRUE) 00140 { 00141 // Start TIMER 00142 // ----------- 00143 $stimer = explode(' ', microtime()); 00144 $stimer = $stimer[1] + $stimer[0]; 00145 // ----------- 00146 00147 $resultset = odbc_exec($this->db_link, $db_query); 00148 00149 // End TIMER 00150 // --------- 00151 $etimer = explode(' ', microtime()); 00152 $etimer = $etimer[1] + $etimer[0]; 00153 // --------- 00154 00155 $this->queryProcessTime = (($etimer - $stimer) * 1000); 00156 00157 if(isset($_GET['debug']) && $_GET['debug'] == 2) 00158 { 00159 echo '<p style="margin:auto; text-align:center">'; 00160 printf("Query <em>" . str_replace(array ("<", ">"), array ("<", ">"), $db_query) 00161 . "</em> loaded in <b>%f</b> milliseconds.", $this->queryProcessTime); 00162 00163 echo '</p>'; 00164 } 00165 00166 return ($resultset); 00167 } 00168 00169 return (@odbc_exec($this->db_link, $db_query)); 00170 } 00171 00172 00180 public function close() 00181 { 00182 @odbc_close($this->db_link); 00183 00184 $this->delete(); 00185 } 00186 00187 00196 private function delete() { unset($this); } 00197 00212 public function build_sparql_query($query, $query_variables, $sponger) 00213 { 00214 $sparql_query = "exst('"; 00215 00216 if(count($query_variables) > 0) 00217 { 00218 $sparql_query .= "select "; 00219 00220 foreach($query_variables as $variable) 00221 { 00222 $sparql_query .= $variable . " as " . $variable . ", "; 00223 } 00224 $sparql_query = substr($sparql_query, 0, strlen($sparql_query) - 2); 00225 $sparql_query .= " from ("; 00226 } 00227 else 00228 { 00229 $sparql_query .= "select * from ("; 00230 } 00231 00232 $sparql_query .= "SPARQL "; 00233 00234 if($sponger == TRUE) 00235 { 00236 $sparql_query .= " define get:soft \"replacing\" "; 00237 // $sparql_query .= " define get:soft \"soft\" "; 00238 } 00239 00240 $sparql_query .= $query; 00241 00242 $sparql_query .= ") sub')"; 00243 00244 return $sparql_query; 00245 } 00246 } 00247 00249 00250 ?>
