コード例 #1
0
// The variable $are_we_online should be true (or 1) if we are connected to the server.
//echo "Are we online: " . $are_we_online; // prints 0 or 1.
// Let us run a query.
$sql = $db->query("SELECT * FROM {admins}");
// The variable $sql will now hold the data returned from the database, we can now work with it.
// Does it have rows ?
/*$hasRows = $db->hasRows($sql);
  echo "Does it have rows: " . $hasRows; // prints 0 or 1 (true or false).
  
  // How many rows does it have.
  $countRows = $db->countRows($sql);
  echo "How many rows: " . $countRows; // returns the number of rows.*/
// We can get the data from the fetch_assoc function.
//$result = $db->fetchAssoc($sql);
// We can get the data from the fetch_array function.
$result = $db->fetchArray($sql);
//We can even print out the latest used query:
//echo $db->lastQuery();
$dbusername = $result['username'];
$dbpwd = $result['password'];
if ($entrduname == $dbusername && $entrdpwd == $dbpwd) {
    $_SESSION["username"] = $dbusername;
    $_SESSION["password"] = $dbpwd;
    $url = 'sports.php';
    echo '<META HTTP-EQUIV=REFRESH CONTENT="0; ' . $url . '">';
} else {
    $url = 'index.php';
    echo '<META HTTP-EQUIV=REFRESH CONTENT="0; ' . $url . '">';
}
// As a last thing, close the connection.
$db->closeConnection();
コード例 #2
0
 public function getSpecificSport($id)
 {
     $sid = $id;
     $table = "locations";
     $config = new config("localhost", "root", "", "play_a_sport_db", "", "mysqli");
     $db = new db($config);
     $db->openConnection();
     $sql = $db->query("SELECT id,location_name,latitude,longtitude FROM {locations} WHERE `id`=" . $sid);
     $result = $db->fetchArray($sql);
     $db->closeConnection();
     $_SESSION['id'] = $result["id"];
     $_SESSION['lname'] = $result["location_name"];
     $_SESSION['ltd'] = $result["latitude"];
     $_SESSION['lngtd'] = $result["longtitude"];
     $url = 'sport_edit.php';
     echo '<META HTTP-EQUIV=REFRESH CONTENT="0; ' . $url . '">';
 }