0

i want the best php class to work with mysql
hi
i want the best and the simple php class to work with the mysql
thanks

4
Contributors
11
Replies
12
Views
8 Years
Discussion Span
Last Post by smartness
0

this should help you

<?php
/*
*
* MARCO VOEGELI 31.12.2005
* www.voegeli.li
*
* This class provides one central database-connection for
* al your php applications. Define only once your connection
* settings and use it in all your applications.
*
*
*/

  
 class Database
 { // Class : begin
 
 var $host;          //Hostname, Server
 var $password;     //Passwort MySQL
 var $user;         //User MySQL
 var $database;     //Datenbankname MySQL
 var $link;
 var $query;
 var $result;
 var $rows;
 
 function Database()
 { // Method : begin
 //Konstruktor
 
 
 
 // ********** DIESE WERTE ANPASSEN **************
 // ********** ADJUST THESE VALUES HERE **********
 
  $this->host = "localhost";                  //          <<---------
  $this->password = "yourpassword";           //          <<---------
  $this->user = "youruser";                   //          <<---------
  $this->database = "yourdatabase";           //          <<---------
  $this->rows = 0;
 
 // **********************************************
 // **********************************************
 
 
  
 } // Method : end
 
 function OpenLink()
 { // Method : begin
  $this->link = @mysql_connect($this->host,$this->user,$this->password) or die (print "Class Database: Error while connecting to DB (link)");
 } // Method : end
 
 function SelectDB()
 { // Method : begin
 
 @mysql_select_db($this->database,$this->link) or die (print "Class Database: Error while selecting DB");
  
 } // Method : end
 
 function CloseDB()
 { // Method : begin
 mysql_close();
 } // Method : end
 
 function Query($query)
 { // Method : begin
 $this->OpenLink();
 $this->SelectDB();
 $this->query = $query;
 $this->result = mysql_query($query,$this->link) or die (print "Class Database: Error while executing Query");
 
// $rows=mysql_affected_rows();

if(ereg("SELECT",$query))
{
 $this->rows = mysql_num_rows($this->result);
}
 
 $this->CloseDB();
 } // Method : end    
  
 } // Class : end
 
?>
0

thank you iam sure its great
but its too old
31.12.2005
please i want it new and famous:)

0

thanks agian
you great man
but i want it not simple and maybe using cache and mysql only
to use it in very bigest project

0

sorry, but since you stated in the OP that you wanted it simple. Your description was vague.

0

sorry, but since you stated in the OP that you wanted it simple. Your description was vague.

I'm sorry for causing you trouble\
but i want A strong and quick and easy class because i will use it
in very big site

0

The code that ivatanako has given you is probably as simple as you can get. It will allow you to connect to your database and run a query. You can extend it if you need, but I can't see how it could be simplified further as you need those steps to be able to do anything in mysql and php.

0

The code that ivatanako has given you is probably as simple as you can get. It will allow you to connect to your database and run a query. You can extend it if you need, but I can't see how it could be simplified further as you need those steps to be able to do anything in mysql and php.

thanks man iam sure you is great man because of this advice
but i want thinge make loops and fetches and all this i found one but not tried yet

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.