/ Published in: PHP
I deleted the old one by accident trying to edit it.
Expand |
Embed | Plain Text
<?php /************************************** seesaw associates | http://seesaw.net client: mysql file: class.mysql.php description: handles mysql paging Copyright (C) 2008 Matt Kenefick(.com) **************************************/ class DB{ var $host; var $user_name; var $password; var $db_name; var $link_id; var $result; var $col; var $query; var $fields; var $records; var $setting; var $debug = false; var $query_count = 0; var $debug_file = "debug.sql"; function settings($key,$value){ $this->setting[$key] = $value; } function init($_host, $_user, $_password, $_db_name){ $this->host = $_host; $this->user_name = $_user; $this->password = $_password; $this->db_name = $_db_name; $this->link_id = @mysql_connect($_host, $_user, $_password) or die("Your website is not properly installed."); } function assign($field, $value){ $this->fields[$field] = ($value)==""?("'".$value."'"):$value; } function assign_str($field, $value){ //$this->fields[$field] = "'".($value)."'"; } } function insert($table){ $f = ""; $v = ""; foreach($this->fields as $field=>$value){ $f.= ($f!=""?", ":"").$field; $v.= ($v!=""?", ":"").$value; } $sql = "INSERT INTO ".$table." (".$f.") VALUES (".$v.")"; $this->query($sql); return $this->insert_id(); } function update($table, $where){ $f = ""; foreach($this->fields as $field=>$value){ $f.= ($f!=""?", ":"").$field." = ".$value; } $sql = "UPDATE ".$table." SET ".$f." ".$where; $this->query($sql); } function timestampFormat($unixNumber){ /// xxxx-xx-xx xx-xx-xx } function query($_query){ $time_start = ((float)$usec + (float)$sec); $this->query = $_query; $this->result = @mysql_query($_query, $this->link_id) or die( $_query."<p>".mysql_error($this->link_id) ); $time_end = ((float)$usec + (float)$sec); $time = $time_end - $time_start; if($this->debug){ $this->query_count ++; $sss = "# ".$this->query_count."\n ".$time." sec \n\n".$_query."\n#-------------------------------------------------------------------------\n\n"; } return $this->result; } function get_records(){ } return $this->records; } function get_tables_status(){ $this->query("SHOW TABLE STATUS FROM `".$this->db_name."`"); if($this->num_rows() > 0){ while($this->movenext()){ $tables[$this->col["Name"]] = $this->col; } return $tables; } return false; } function fetch_array(){ } function num_rows(){ } function fixSlashes(){ if($this->col){ foreach($this->col as $key => $value) return $this->col; } } function movenext(){ if($this->setting['fixSlashes']) return $this->fixSlashes(); else return $this->col; } function done(){ } function insert_id(){ } function affected_rows(){ } } ?>
Comments
Subscribe to comments
You need to login to post a comment.

The method assign() is really hard to read but this class is good work
ya very good job, but you should add description for each line what it does, for everybody (even for begginers) to understand.
If you are interrested in generating PHP classes out of your database schema, have a look to:
https://sourceforge.net/projects/classify-db/
This PHP console application connects to the database you want and generate a PHP class for every table or view in the schema. It generates - one property for each row of the table. - function to fetch a specific row (based on its primary key), or to fetch one, several or all rows at once, with the option to filter results on one or several rows - functions to insert, update and delete rows - functions to easily load referenced and referencing objects (a distinct method is generated for each foreign key pointing to or from a given table) - functions to easily work with primary keys - supports multi-column primary keys and foreign keys - supports cross database foreign keys - automatically deals with auto_increment primary keys - automatically converts MySQL Date types to PHP DateTime objects where applicable - customizable, you can generate the php classes into one (big) file or with one file per class - instead of generating the code you can also simply preview it in the console (syntax highlighted on ANSI enabled consoles), or export it as an HTML document. - if you whish to develop additional XSLT stylesheets to support more programming languges, the application can also export the intermediary XML document describing the database's structure