| 
<?php
// includes the file that contains data for connecting to mysql database, and  PDO_MySQLi class
 include('../conn_mysql.php');
 
 // creates object with connection to MySQL
 $conn = new PDO_MySQLi($mysql);
 
 /*
 for values used in LIKE statement, add the "?" or "%" characters in the value. Use like this
 $val = '%'. $val .'?';
 */
 
 // SELECT with named placeholders and values for placeholders added into an associative array
 $sql = "SELECT * FROM `testclass` WHERE `title` LIKE :title ORDER BY `id`";
 $vals = array('title'=> '%Course%');
 
 // executes the SQL query (passing the SQL query, and array with values), and gets the selected rows
 $rows = $conn->sqlExecute($sql, $vals);
 
 $nr_rows = $conn->num_rows;          // number of selected rows
 $nr_cols = $conn->num_cols;          // number of selected columns
 
 // if there are returned rows, traverses the array with rows data, using foreach()
 if($nr_rows > 0) {
 echo 'Number of selected rows: '. $nr_rows .' / Number of columns: '. $nr_cols;
 
 // outputs data using index number of column order (index starting from 0)
 foreach($rows AS $row) {
 echo '<br/>Col1 = '. $row[0] .' / Col2 = '. $row[1] .' / Col3 = '. $row[2] .' / Col4 = '. $row[3];
 }
 }
 else {
 if($conn->error) echo $conn->error;      // if error, outputs it
 echo '0 selected rows';
 }
 |