PHP MySQL Database Class
April 19th, 2005A class for very basic MySQL database connectivity. Written to reduce redundant code in my own projects aswell as aid in debugging and error reporting during the developement phase. Currently connects to a database, execute external files containing SQL commands, insert and update from an array of key => value pairs, insert and update with sql command, query (one result), query (multiple rows), and dump a select query to a table. The zip file contains the class aswell as a demonstration script.
Download Version 1.0.4: db-1.0.4.zip
Do you like this code? Rate This Script at Hot Scripts.
![]() |
Categories
Popular Posts
RSS Feeds
Archives
November 27th, 2007 at 10:55 am
how can i make a class to insert data to database in php
November 27th, 2007 at 11:26 am
RE: serkan
The sample file included with the class shows how this is done.
December 1st, 2007 at 11:37 am
Hi,
Your script is working for me but I can't find which database was used to create the table users in ! I'm new to MySQL. Could you help me out with this?
January 14th, 2008 at 1:02 pm
Hi,
The script works perfectly fine on my PC, but online I get a "no database selected" error. I think it has something to do with the MySQL version of the server being quite old (3.23).
Could you tell me what I should change within the script?
January 15th, 2008 at 7:22 am
Are you sure you typed the database name correctly? Are you sure there is a database setup online?
January 16th, 2008 at 6:42 pm
This database class is a precious piece of php code.
May 2nd, 2008 at 7:03 am
Hi Micah, sorry for bother you but i get some rare error..
Parse error: syntax error, unexpected $end in C:\wamp\www\currency\include\db.class.php on line 458
Just including the file I get this.. any ideas?
Best regards and thanks for this..
May 22nd, 2008 at 2:31 pm
[...] the maze of duplicate entries I encountered yesterday through StumbleUpon, I came across this page, which reads: A class for very basic MySQL database connectivity. Written to reduce redundant code [...]
June 3rd, 2008 at 11:04 am
Hey, Micah,
Thanks for the class... It will be very usefull to me...
Thank you again!
June 19th, 2008 at 1:09 am
Hi Micah,
Thanks for your MySql Class.
One question. Is it only working on PHP 5 or also on lower versions ?
Raoul
June 28th, 2008 at 2:07 am
Thanks for a very clear tutorial. This is very helpful since I am making my code to OO design.
more power.
June 29th, 2008 at 10:33 am
Hi,
Is this still being used ?
Thanks
July 20th, 2008 at 3:05 pm
Many thanks - this will come in handy. Using it in a new play project I am creating....
-N@
September 4th, 2008 at 7:31 pm
Hi,
thank's your class, and please answer my question...
how to make query DELETE..
I was tried :
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/classmysql/db.class.php on line 137
Many thank's
October 9th, 2008 at 7:34 am
[...] PHP MySQL Database Class Esta es una clase muy b
October 9th, 2008 at 10:18 am
Good job, a nice handy class, i will use it on my scripts.
I found kind of bug, at select, when query fails, row_count remains the same, i think it`s better to set it to 0 ;
if (!$r) {
$this->last_error = mysql_error();
$this->row_count = 0;
return false;
}
October 10th, 2008 at 11:46 pm
hi
many many thanks
October 22nd, 2008 at 8:38 pm
Thanks mate
November 12th, 2008 at 4:12 pm
Thanks a lot. Very useful.
November 16th, 2008 at 11:17 pm
Thanks, You done a Good job.
April 3rd, 2009 at 7:33 am
its very useefull for me.
April 23rd, 2009 at 1:21 pm
excelente muy buena
June 9th, 2009 at 9:41 am
I had the same error as Diego: "Parse error: syntax error, unexpected $end in C:\wamp\www\currency\include\db.class.php on line 458"
The fix on my system was to replace any instance of
June 9th, 2009 at 3:11 pm
Very nice class.
I would suggest that you consider developing another flavour that uses MySqli.
As for this one, there is just one missing thing in it, ESCAPING strings. You can add a public function that can be used to escape values before being put into a query.
June 9th, 2009 at 11:32 pm
The same error as Diego had:
C:\Documents and Settings\harmat\Desktop\PHP5>php-5\php.exe DB_esimerkki_luokat
_testi.php
PHP Parse error: parse error, unexpected $end in C:\Documents and Settings\harm
at\Desktop\PHP5\db.class.php on line 457
Parse error: parse error, unexpected $end in C:\Documents and Settings\harmat\De
sktop\PHP5\db.class.php on line 457
C:\Documents and Settings\harmat\Desktop\PHP5>pause
Press any key to continue . . .
June 10th, 2009 at 8:31 pm
of the 3 classes that i have so far needed to start what i want to do, you have built 2 of them!
Thanks google, and thanks to you for making them.
cheers.
June 10th, 2009 at 11:48 pm
$data = array(
'id' => '',
'timestamp' => '',
'txn_id' => 'ok',
'verify_sign' => 'verified',
);
$id = $db->insert_array('ipns', $data);
if (!$user_id) $db->print_last_error(false);
$db->print_last_query();
$db->dump_query("SELECT * FROM ipns WHERE id=$id");
produces the insert SQL of:
INSERT INTO ipns (id,timestamp,txn_id,verify_sign) VALUES (,,'ok','verified')
wheras it needs to be:
INSERT INTO ipns (id,timestamp,txn_id,verify_sign) VALUES ('','','ok','verified')
for the cases where the variable is set, but has no value.
June 20th, 2009 at 6:07 am
Thanks for sharing, keep up the good work!