PHP Classes

File: example2.php

Recommend this page to a friend!
  Packages of Alessio Maria Braccini   mysqlc   example2.php   Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Example script (with constructor)
Class: mysqlc
MySQL database access wrapper
Author: By
Last change:
Date: 21 years ago
Size: 782 bytes
 

Contents

Class file image Download
<?
include "mysql_cnstr.php";

// In this page we use a constructor. At this point the database connection is
// already available. You can easily include mysql_cnstr.php at the beginning
// of each php script that must access a MySql database and you will find
// yourself with a ready-to-use database connection

// Execute a simple query

$query = 'select Host, User, Password from user';
if ($db->Query($query))
{
    echo '<pre>';
    echo 'Database: ' . $db->dbname . "\n";
    echo 'Query: ' . $query . "\n\n";

    // Show the results
    while ($row = $db->NextRow())
    {
        printf("%s\t%s\t%s\n", $row['Host'], $row['User'], $row['Password']);
    }
    
    echo '</pre>';
}
else echo "Query error: " . $db->get_Error();    // Print error message if necessary

// Close db connection
$db->Close();
?>