7Jan/100
Exporting Contacts from the Durham Uni Database
Quick bit of example php code to pull people's details out of the Durham University user database (not LDAP, this is a separate database with slightly different details) - this database is just sitting on the mysql server without a password!
The applications of this database are endless, in this simple example the script grabs everyone from one college and turns it into a handy CSV file you could import into your address book, etc...
Quick example code to dump mildert student data into a csv
-
function fixcase($string){
-
$words = explode(" ", $string);
-
-
for($i=0; $i<count($words); $i++) {
-
$s = strtolower($words[$i]);
-
$s = substr_replace($s, strtoupper(substr($s, 0, 1)), 0, 1);
-
$result .= "$s ";
-
}
-
-
$string = trim($result);
-
return $string;
-
}
-
-
mysql_connect("mysql.dur.ac.uk", "nobody", "") or die(mysql_error());
-
-
$sql = "SELECT * FROM UserDetails WHERE (college = 'Van Mildert College' OR department = 'Van Mildert College')";
-
-
$res = mysql_db_query("Pdcl0www_userdata", $sql) or die(mysql_error());
-
-
echo "First Name, Surname, Display Name, Email, Department, Company, Website, Year";
-
-
while($row = mysql_fetch_array($res)){
-
$name = array();
-
$name = split(" ", str_replace(",", " ",$row['firstnames']));
-
echo fixcase($name[0]).','.fixcase($row['surname']).','.fixcase($name[0]).' '.fixcase($row['surname']).','.$row['email'].','.$row['department'].','.$row['college'].',http://www.dur.ac.uk/vm.jcr/index.php?option=com_content&task=view&id=48&Itemid=55&person='.$row['username'].','.$row['studyyear']."";
-
}
-
-
echo $res;