One Class out of three that conform an ADODB like object system to work with MySQL. Recordset provides access to data through sql execution.
By : Slainte
<?
// Base recordset class for MySQL operations
// Full information at http://www.phpclasses.org/mysql_db
class mysql_recordset {
// Init variables required
VAR $connobj = "" ;
VAR $sqlstring = "" ;
// Data related variables
VAR $rs = 0 ;
VAR $row = 0 ;
VAR $recordcount = 0 ;
VAR $EOF = true ;
// Private methods
function get_recordset()
{
if ($GLOBALS[$this->connobj]->db && $this->sqlstring!="")
{
$this->rs = mysql_query($this->sqlstring,$GLOBALS[$this->connobj]->db) ;
$GLOBALS[$this->connobj]->error_level = mysql_errno() ;
$GLOBALS[$this->connobj]->error_desc = mysql_error() ;
if ($this->rs)
{
$this->EOF = false ;
$this->recordcount = mysql_num_rows($this->rs) ;
$GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION O.K.: Executed " . $this->sqlstring ." got " . $this->recordcount . " rows" ;
} else {
$this->recordcount = 0 ;
$this->EOF = true ;
$GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: Executed " . $this->sqlstring . " got " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ;
}
} else {
$this->recordcount = 0 ;
$this->EOF = true ;
$GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No database open OR no SQL command provided" ;
}
$GLOBALS[$this->connobj]->debug() ;
}
function get_row()
{
if ($this->rs && $GLOBALS[$this->connobj]->db)
{
$this->row = mysql_fetch_array($this->rs) ;
$GLOBALS[$this->connobj]->error_level = mysql_errno() ;
$GLOBALS[$this->connobj]->error_desc = mysql_error() ;
// $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION Executed got " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ;
// $GLOBALS[$this->connobj]->debug() ;
if ($this->row)
{
$this->EOF = false ;
} else {
$this->EOF = true ;
}
} else {
$GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No database open" ;
}
}
// Public interface
function query()
{
$this->get_recordset() ;
return $this->recordcount ;
}
function movenext()
{
$this->get_row() ;
return $this->EOF ;
}
function field($campo)
{
echo $this->row[$campo] ;
}
function value($campo)
{
return $this->row[$campo] ;
}
function mysql_recordset($connobjname,$sqlcommand)
{
$this->connobj = $connobjname ;
$this->sqlstring = $sqlcommand ;
}
function clear_recordset()
{
$this->sqlstring="" ;
mysql_free_result($this->rs) ;
}
function move_to($rnumber)
{
if ($this->rs)
{
if (!mysql_data_seek($this->rs,$rnumber))
{
$GLOBALS[$this->connobj]->error_level = mysql_errno() ;
$GLOBALS[$this->connobj]->error_desc = mysql_error() ;
$GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: Could not move to record " . $rnumber . " " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ;
} else {
$GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION O.K.: Result pointer moved to " . $rnumber ;
}
} else {
$GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No result open" ;
}
$GLOBALS[$this->connobj]->debug() ;
}
function movefirst()
{
$this->move_to(0) ;
}
function movelast()
{
$this->move_to($this->recordcount-1) ;
}
}
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Database Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle. FREE! Go There Now!
|
|
|
|
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase. FREE! Go There Now!
|
|
|
|
Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic. FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |