Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/6-select_1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of MarPlo  >  PDO_MySQLi class  >  examples/6-select_1.php  >  Download  
File: examples/6-select_1.php
Role: Example script
Content type: text/plain
Description: Example 6
Class: PDO_MySQLi class
Access MySQL using PDO or MySQLi extensions
Author: By
Last change:
Date: 2013-09-04 02:10
Size: 960 bytes
 

Contents

Class file image Download
<?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);

// simple SELECT, without placeholders
$sql "SELECT * FROM `testclass` WHERE `id` > 1";

// executes the SQL query (passing only the SQL query), and gets the selected rows
$rows $conn->sqlExecute($sql);

$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;

  foreach(
$rows AS $row) {
    echo 
'<br/>ID = '$row['id'] .' / Title = '$row['title'];
  }
}
else {
  if(
$conn->error) echo $conn->error;      // if error, outputs it
  
echo '0 selected rows';
}