WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : This is a class with functions that are taken from simple SQL statements. I made it to have an easier connection between PHP3 and DBase files.
Categories : General SQL, PHP, PHP Classes, Databases Update Picture
Steven Apostolou
Date : Aug 28th 1998
Grade : 1 of 5 (graded 1 times)
Viewed : 8618
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Steven Apostolou
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php

/* Writen by Mythos Internet Design (S.A. Apostolou)

****
This class is provided with no guarantees that it will either
work properly or not trash your machine. So don't blame me if
it does. It works great for me though, and you can do whatever
you want to it in the name of free software.
****

I wanted to have a sort of SQL connection with the dbase connectivity of PHP3.
The functions in this class are like simple SQL statements.

select_all = SELECT * FROM table
select_fields = SELECT field1, field2, ect. FROM table
select_all_where_values = SELECT * FROM table WHERE values
select_fields_where_values = SELECT field1, field2, ect. FROM table WHERE
values
delete_rows_where_values = DELETE FROM table WHERE values


Functions:

connect (string filename) // Connect to a
dbase table
close () // Close the
connection with the dbase table
num_rows () // Returns the
number of records (rows) in the dbase table
fields_num () // Returns the
number of fields (collums) in the dbase table

create_table (string filename, array fields) // Creates a new
dbase table and connects to it
insert_values (array values) // Add values (a
record) to the dbase table
delete_rows_where_values (array array-values) // Delete row(s)
where specified values are in

select_all () // Returns a two-
dimensional array with all the rows and with all the fields of the dbase table
select_fields (array fields) // Returns a two-
dimensional array with all the rows and with all the specified fields of the
dbase table
select_all_where_values (array array-values) // Returns a two-
dimensional array with all the fields and with all rows which are filtered on
specified values in the rows of the dbase table
select_fields_where_values (array fields, array array-values) // Returns a two-
dimensional array with all the specified fields and with all rows which are
filtered on specified values in the rows of the dbase table

result_current () // Returns a
HTML-table with the last select function that was done on the dbase table
result_all () // Returns a
HTML-table of the complete dbase table

Array fields is an array like: 'array (1, 2, 3, ect. )'
Array values is a two-dimentional array like : 'array ("1" => "VALUE", "2" =>
"VALUE2", ect.)'

Example:

****---------------------------------------****

Table: /databases/numbers.dbf

0 1 2 <--- Field numbers !!!
------------------------------
|Number1 | Number2 | Number3 |
|--------|---------|---------|
0 | 2 | 5 | 8 |
1 | 4 | 2 | 5 |
2 | 2 | 6 | 2 |
3 | 1 | 5 | 9 |
------------------------------
^
|-- Row numbers !!!!

****---------------------------------------****

$table_numbers = new dbase;
$table_numbers->connect (/databases/numbers.dbf);

echo ("$table_numbers->fields_num()<BR>");
echo ("$table_numbers->num_rows()<BR>");

$fields = array (1, 2)
$values = array ("0" => "2");
$data = $table_numbers->select_fields_where_values ($fields, $values);

print $data;
$table_numbers->result_current ();
$table_numbers->close();

****---------------------------------------****
Result of code above:

3
4
Array <--- This is a two-dimensional array
-------------
| 5 | 8 | <---(This is an HTML-table)
-------------
| 6 | 2 |
-------------

****---------------------------------------****

*/


class dbase
{
var $database_identifier,
$number_of_records,
         $number_of_fields,
         $data,
         $dbase_file;


function connect ($dbase_filename)
{
$this->database_identifier = dbase_open($dbase_filename, 2);
         $this->number_of_records = dbase_numrecords($this-
>database_identifier);
         $this->number_of_fields = dbase_numfields($this-
>database_identifier);
         $this->dbase_file = $dbase_filename;
}



function close ()
{
dbase_close($this->database_identifier);
}



function num_rows ()
{
return $this->number_of_records;
}



function fields_num ()
{
return $this->number_of_fields;
}



function create_table ($file_name, $fields_array)
{
if (dbase_create($file_name, $fields_array))
         $this->connect($file_name);
}



function insert_values ($data)
{
dbase_add_record( $this->database_identifier, $data );
$this->close();
         $this->connect($this->dbase_file);
}



function delete_rows_where_values ($values)
{
$nothing_to_delete = 0;

$i = 1;
while ($this->number_of_records >= $i)
{
$row = dbase_get_record($this->database_identifier, "$i");
$with_if = "{dbase_delete_record(\$this->database_identifier, \$i);
\$nothing_to_delete = 1; }";

eval( 'if ( '. $this->return_expr2($values) .')'. $with_if );

$i++;
}

if ($nothing_to_delete)
dbase_pack($this->database_identifier);

$this->close();
         $this->connect($this->dbase_file);
}



function select_all ()
{
$i = 1;
while ($this->number_of_records >= $i)
{
$row_data = dbase_get_record($this->database_identifier, "$i");
$table_data[] = $row_data;
$i++;
}

if ( !is_array($table_data) )
$table_data = 0;

$this->data = $table_data;
                 
         return $this->data;
}



function select_fields ($fields)
{
$i = 1;
while ($this->number_of_records >= $i)
{
$row_data = dbase_get_record($this->database_identifier, "$i");
$table_data[] = $this->return_fields($fields, $row_data);
$i++;
}

if ( !is_array($table_data) )
$table_data = 0;

$this->data = $table_data;
        
         return $this->data;
}



function select_all_where_values ($values)
{
$with_expr = "\$table_data[] = \$row_data;";

$i = 1;
while ($this->number_of_records >= $i)
{
$row_data = dbase_get_record($this->database_identifier, "$i");
eval( 'if ( '. $this->return_expr($values) .')'. $with_expr );

$i++;
}

if ( !is_array($table_data) )
$table_data = 0;

$this->data = $table_data;
        
         return $this->data;
}



function select_fields_where_values ($fields, $values)
{
$with_expr = "\$table_data[] = \$this->return_fields(\$fields,
\$row_data);";

$i = 1;
while ($this->number_of_records >= $i)
{
$row_data = dbase_get_record($this->database_identifier, "$i");
eval( 'if ( '. $this->return_expr($values) .')'. $with_expr );

$i++;
}

if ( !is_array($table_data) )
$table_data = 0;

$this->data = $table_data;
        
         return $this->data;
}



function result_current ()
{
if ($this->data)
         {
echo ("<TABLE BORDER=\"1\">\n");
reset($this->data);

do
{
$row_data = current($this->data);
                        echo ("<TR>");

         for ( reset($row_data); $row_element = current($row_data); next
($row_data) )
echo ("<TD>$row_element</TD>");

echo ("</TR>\n");
}
while ( next($this->data) );

echo ("</TABLE>\n");
         }
         else
         return 0;
}



function result_all ()
{
$table_data = $this->select_all();

if ( is_array($table_data) )
         {
echo ("<TABLE BORDER=\"1\">\n");
reset($table_data);

do
{
$row_data = current($table_data);
echo ("<TR>");
        
         for ( reset($row_data); $row_element = current($row_data); next
($row_data) )
echo ("<TD>$row_element</TD>");
                        
                        echo ("</TR>\n");
}
while ( next($table_data) );

echo ("</TABLE>\n");
}
         else
         return 0;
}



function return_fields ($fields, &$row_data)
{
while ( $fields_elements = each ($fields) )
{
$fields_array[] = $row_data[$fields_elements[value]];
}

return $fields_array;
}



function return_expr ($values)
{
while ( $bar = each( $values ) )
{
$expr .= "ereg(\"$bar[value]\", \$row_data[$bar[key]]) && ";
}

$expr = substr($expr, 0, strrpos( $expr, "&" ) - 2);

return $expr;
}



function return_expr2($values)
{
while ( $bar = each( $values ) )
{
$back .= "ereg(\"$bar[value]\", \$row[$bar[key]]) && ";
}

$back = substr($back, 0, strrpos( $text, "&&" ) - 3);

return $back;
}
} // end class dbase

?>



ADODB Database Wrapper Abstraction Library for PHP: MySQL, MSSQL, Oracle, Interbase,ODBC, Microsoft Access and FoxPro.
Categories : PHP Classes, Databases, PHP, General SQL, ODBC
Database and Recordset classes fo SyBASE Usage is obvious.
Categories : Sybase, Databases, PHP Classes, PHP
google like search function with bolded search terms
Categories : PHP, Search, Databases, General SQL
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
phpEasySQL - Easily connect to your MySQL database with just 1 php file and 3 easy steps!
Categories : Databases, PHP, MySQL, General SQL
Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
Dynamic WHERE CLAUSE depending on number of FORM FIELDS
Categories : ODBC, General SQL, PHP, Complete Programs, Databases
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
Recordset Class like ADO Recordset (plus DataBase Splitting feature) using ODBC functions
Categories : PHP Classes, ODBC, Databases, PHP
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
MySQL Connection/Query Class
Categories : Databases, MySQL, PHP, PHP Classes
Simple class for accessing databases like MSSql Server, Oracle etc by Raju
Categories : PHP, MS SQL Server, Databases, PHP Classes, Oracle
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL