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

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
 
?>

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

PHP 5 was released 2004, and i don't see any problem with the code that i have given above.

And what do you mean about new and famous?

then just use this

www.php.net/mysql

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

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

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

any more ideas?

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.

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

maybe you should try it first then add a comment on it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.