September 10 2010 21:13:22
Navigation
Last Seen Users
thenebb< 5 mins
bigcarrot< 5 mins
pojan00:12:14
damesi2600:23:06
Bubbi00:25:15
m1row00:47:30
wup00700:49:04
m3rik00:51:10
eWe00:51:17
ncuxap00:54:30

Members: 16,277
Newest: pojan
Blogs
Diemux
» 18-09-2009 - Say ...
Diemux
» 10-07-2009 - Will...
Diemux
» 24-06-2009 - Blog...
elyn
» Elyn + Streamyx (...
Diemux
» 19-05-2009 - Thin...
Diemux
» 15-05-2009 - Week...
Diemux
» 13-05-2009 - Comp...
elyn
» Number 1925
Diemux
» Number One
Things to Do
Latest Articles
A tour through the n...
Protect your Fusion ...
Change your database...
Handling MySQL Datab...
Admin Control Panel ...
How to Secure Your I...
Show Content by Defa...
v7 | Add social book...
v7 | Custom MySQL er...
How To: A PM after r...
v7 | SEO friendly UR...
v7 | SEO friendly UR...
Comments Advanced Vi...
Auto-redirect to the...
A tour through PHP-F...

View all articles
Downloads v7
Currently popular Downloads

FusionBoard 4 4030
Video Gallery 2877
Professional Down... 2576
Photoalbum Mass U... 2524
Avatar Studio 2353
Extended Profile 1899
Button panel 1869
XHTML mod for mod... 1867
VArcade 2.1 1836
HighSlide Gallery... 1806

Latest Downloads


Bosnian Locale - PHP... 5
Multimedia Studio ve... 29
Post-Report 2
Post Report with pd_... 1
XHTML mod for modern... 1867
Pimped-Fusion v0.08.01 23
Update Package v0.08.01 4
Support Panel-Skype 25
Header Weather Widget 84
Forum Thread List Pa... 35

Latest 100
Downloads v6
Currently popular Downloads

Banner System v2.0.4 1708
Video Gallery 1214
Extreme Theme Editor 917
Fuzed Shoutbox 818
Seoname.php 756
Icon Package 2.0 702
Extended Profile ... 660
News.php 585
EXTboard 552
Tabbed welcome panel 532

Latest Downloads


Google Sitemap Fast 60
ExtBoard 1.2 385
EXTboard 552
v6.01.18 - v6.01.19 34
v6.01.19 FULL 93
Birthday 123
Moneybookers 47
User info 104
Link to us 262
jNews.php 346

Latest 100
Provider
PHPfusion-mods.net is hosted at:

110MB
Handling MySQL Database on php-Fusion
Before i start anything, i will hereby take for granted that you (reader) understand/know/learn MySQL to a certain level. Even, if you don't know anything about MySQL, this might help you start. And now, we may start.

MySQL database functions code snippets

function dbquery($query) {
}

function dbcount($field, $table, $conditions = "") {
}

function dbresult($query, $row) {
}

function dbrows($query) {
}

function dbarray($query) {
}

function dbarraynum($query) {
}



These are the functions' declarations on maincore.php. No, you don't have to open maincore.php, this is just a sample i wanted you all to look. From there, it should provide you with some idea of how this functions works. If you don't seems to understand the idea, don't worry. i'll will explain each functions.

1. dbquery($query)
This function executes a query on a MySQL database and then it returns a value. If the query failed, it will produce error message and return "false".

dbquery() is followed up by other function listed above accept for dbcount(). There are only one parameter for this function: the SQL query. Like mysql_query(), dbquery() is also used for UPDATE, DELETE, INSERT, and CREATE. You won't be using CREATE though.

Examples
see examples for other functions except dbcount(). :P


2. dbcount($field, $table, $conditions = "")
This function executes a COUNT query on a MySQL database and then it returns a value. COUNT query means it counts the total value of records found. If the query failed, it will produce error message and return "false".

dbcount() does not requires a result from dbquery(). dbcount() is usually used for paginations.
dbcount() has 3 parameters, two of which are required.
first paramenter -> $field
signifies which field in the table to be count
second parameter -> $table
signifies which table to be count
$conditions = ""
signifies the conditions of the field that need to be met.
conditions in MySQL is the
"WHERE field_name = 'some_value' AND field_name2 = 'other_value'"

Examples
this example returns the values of increment of 10 starting from 0. e.g, 0, 10, 20, 30 .. and so forth


$count = dbcount("(data_id)", DB_DATA, "data_access='".$d_ac.");
$count = ($count / 10) - 1;
$d_count = ceil($count) * 10;
if (!$d_count){
$d['error'] = "Cannot count data";
}


3. dbresult($query, $row)
A clone of the mysql_result() function that returns the value of a field in a recordset. If the query failed, it will produce error message and return "false".

dbresult() requires the return value from dbquery(). Because the return value specifies which result handle to use.

Examples

$query = "SELECT * FROM ".DB_DATA." WHERE data_id = '{$_GET['p']}'";
$result = dbquery($query);
$d['name'] = dbresult($result, 1);
if (!$d['name']){
$d['error'] = "No Name found";
}


4. dbrows($query)
A clone of the mysql_num_rows() function that returns the number of rows in a recordset. If the query failed, it will produce error message and return "false".

dbrows() requires the return value from dbquery(). Because the return value specifies which result handle to use.

Examples

$query = "SELECT * FROM ".DB_DATA.";
$result = dbquery($query);
$d_rows = dbrows($result);
if (!$d_rows){
$d['error'] = "Cannot count rows in data table";
}



5. dbarray($query)
A clone of the mysql_fetch_assoc() function that returns a row from a recordset as an associative array. If the query failed, it will produce error message and return "false".

dbarray() requires the return value from dbquery(). Because the return value specifies which result handle to use.

Examples

$query = "SELECT * FROM ".DB_DATA." WHERE data_id = '{$_GET['p']}'";
$result = dbquery($query);
if($db = dbarray($result)){
$d['id'] = $db['data_id'];
$d['name'] = $db['data_name'];
$d['desc'] = $db['data_desc'];
$d['access'] = $db['data_access'];
}
else{
$d['error'] = "No data found";
}


6. dbarraynum($query)
A clone of the mysql_fetch_row() function that returns a row from a recordset as a numeric array. If the query failed, it will produce error message and return "false". This function is very similar to dbarray, you will understand after reading the example

dbarraynum() requires the return value from dbquery(). Because the return value specifies which result handle to use.

Examples

$query = "SELECT * FROM ".DB_DATA." WHERE data_id = '{$_GET['p']}'";
$result = dbquery($query);
$d = dbarraynum($result)
if(empty($d['id'])){
$error = "No data found";
}
Comments
#1rvt on April 19 2009 15:04:18
rvt
Under 4. dbrows($query)
you mention that dbrows returns false when the query fails,
however you check the return value like this if (!$d_rows) {....}
You should be using this:
if ($d_rows===false) {..... querie failed ...}

other examples:
if ($d_rows===0) {..... query returned 0 rows (but not false) ...}
if ($d_rows>0) {..... query returned more then one row...}

In your case you would throw that error when when the number of rows from the query would be zero (0) whish is perfeclty fine for some queries.
#2elyn on May 27 2009 23:27:15
elyn
test
Post Comment
Please Login to Post a Comment.
Ratings
Rating is available to Members only.

Please login or register to vote.

Awesome! Awesome! 0% [No Votes]
Very Good Very Good 100% [1 Vote]
Good Good 0% [No Votes]
Average Average 0% [No Votes]
Poor Poor 0% [No Votes]
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Our Coders
Smokeman
Rizald 'Elyn' Maxwell
Diemux
Netrix
Donate
Shoutbox
You must login to post a message.

10/09/2010 12:02

10/09/2010 11:37
@Splash: Well now I've tried that - but it didn't work. Spam removed again today.

08/09/2010 03:23
120 . 32 . * . *

08/09/2010 03:22
Block IP range from China and bye bye spammer. Big Smile

06/09/2010 13:00
@smokeman: my shout was not adressed to a special person. Fusion-Mods and Fusion-Main sites have the same problems with stupid spammers. Wink

06/09/2010 10:02
@MarcusG: I agreed with you but I can't do anything about it. It's Diemux that stands for that part of the site.

06/09/2010 09:21
This SPAM really SUX, especially when there are solutions to fight it. I have NO (ZERO) Spam on my site.

06/09/2010 04:18
I think someone break Fusion captcha.

04/09/2010 09:32
Spam deleted.

04/09/2010 08:09
Try this to fight the SPAM: KLICK ME HARD Or THIS

Advertiser
One-click Translation
Translate This Site

Render time: 0.15 seconds 5,416,259 unique visits