PHP Classes

File: examples/6-select_1.php

Recommend this page to a friend!
  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: 10 years ago
Size: 960 bytes


Class file image Download
// includes the file that contains data for connecting to mysql database, and PDO_MySQLi class

// 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) {
'Number of selected rows: '. $nr_rows .' / Number of columns: '. $nr_cols;

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