Login   Register  
PHP Classes
elePHPant
Icontem

File: mysqlTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mhyk Duterte  >  Hybrid MySQL  >  mysqlTest.php  >  Download  
File: mysqlTest.php
Role: Example script
Content type: text/plain
Description: Sample class usage
Class: Hybrid MySQL
MySQL database access wrapper
Author: By
Last change:
Date: 2005-06-25 21:54
Size: 958 bytes
 

Contents

Class file image Download
<?php

// Require the class
require_once('MySQL.php');
// Database info
require_once('db.php');

// Instantiate the MySQL Class
// Parameters: Database Host, Database User, Database Password, Database Name, Persistent Connection (true or false)
$mysql = new MySQL($dbHost,$dbUser,$dbPass,$dbName);

// Check to see if errors occured
if ($mysql->isError()) {
    
// Print the error message
    
die($mysql->getMessage());    
}

// The SQL to execute
$sql "SELECT field FROM table";

// Execute the query
$result $mysql->query($sql);

// Check for errors
if (! $result) {
    
// Print the error message
    
die($mysql->getMessage());
}

// Loop through the rows using the fetch() method
// Parameters: [optional] fetch mode (FETCH_ARRAY , FETCH_ASSOC or FETCH_OBJECT)
while ($row $result->fetch(FETCH_OBJECT)) {
    echo 
$row->field.'<br />';
}

echo 
'Rows: '.$result->numRows();

// Free the result in memory
$result->free();

// Close the connection
$mysql->close();

?>