| | |
i want the best php class to work with mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 77
Reputation:
Solved Threads: 5
this should help you
PHP Syntax (Toggle Plain Text)
<?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 ?>
•
•
Join Date: Jul 2007
Posts: 77
Reputation:
Solved Threads: 5
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
And what do you mean about new and famous?
then just use this
www.php.net/mysql
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.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. •
•
Join Date: Sep 2009
Posts: 19
Reputation:
Solved Threads: 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.
but i want thinge make loops and fetches and all this i found one but not tried yet
![]() |
Similar Threads
- PHP recursive step through mysql table. (PHP)
- Apache (Linux Servers and Apache)
- PHP/AJAX/Javascript/Mysql - Master - NO FREELANCE (Los Angeles) (Software Development Job Offers)
- can asp work with mySQL (ASP)
- MySQL INSERT not working. Why? (MySQL)
- configure PHP to work with Mysql (MySQL)
- [HIRING] full-time PHP Ninja (work from anywhere) (Software Development Job Offers)
- How many clients can access a PHP script at a time from a MySQL server? (MySQL)
Other Threads in the PHP Forum
- Previous Thread: Problems with cron file
- Next Thread: PHP link/content Extractor
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





