User Tools

Site Tools


2018-04-06
LDAP: couldn't connect to LDAP server

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
2018-04-06 [2019/04/06 15:04]
nmckillop created
2018-04-06 [2019/04/06 15:58] (current)
nmckillop
Line 1: Line 1:
 +====== Meeting Notes: Sat 6th April 2019 ======
  
 +We worked through some demos of how to connect to a database and pull out some data with PHP.  Here is the code we used:
 +
 +<​code>​
 +
 +<?​php ​
 +error_reporting(-1);​
 +ini_set('​display_errors',​ 1);
  
-''<?​php 
 $host = "​localhost";​ $host = "​localhost";​
 $username = "​coding_user";​ $username = "​coding_user";​
 $password = "​cheese";​ $password = "​cheese";​
-$db_name = "​coding";​+$db_name = "​coding"; ​
  
 $mysql_string = "​mysql:​host=$host;​dbname=$db_name";​ $mysql_string = "​mysql:​host=$host;​dbname=$db_name";​
Line 11: Line 18:
 $db_connection = new PDO($mysql_string,​ $username, $password); $db_connection = new PDO($mysql_string,​ $username, $password);
  
 +$sql = "​select * from test_table order by surname desc";
 +$rs = $db_connection->​query($sql);​
 +$rows = $rs->​fetchAll(PDO::​FETCH_ASSOC);​
 +
 +echo "<​ol>"; ​
 +foreach($rows as $row) {
 +        echo "<​li>";​
 +        echo $row['​surname'​].",​ "​.$row['​forename'​];​
 +        echo " ("​.date("​D jS M Y", strtotime($row['​date_added'​]));​
 +        echo "​)";​
 +        echo "</​li>";​
 +}
 +echo "</​ol>";​
  
 ?> ?>
-''​+ 
 + 
 +</​code>​
2018-04-06.1554559461.txt.gz · Last modified: 2019/04/06 15:04 by nmckillop