Navigation
Last Seen Users
vampalicious00:09:42
conans00:32:13
pat10200:34:52
kaozzoak02:07:29
piotrek199612302:52:17
hqrpele04:05:21
Technox H05:50:31
Ohno06:07:47
Pardoc07:24:14
Not_mad07:36:46

Members: 27,569
Newest: Technox H
Downloads v7
Downloads v6
One-click Translation
Translate This Site

Member Poll
Which version of PHP-Fusion are you using?

6.xx.xx
6.xx.xx
4% [19 Votes]

7.00.xx
7.00.xx
8% [38 Votes]

7.01.xx
7.01.xx
8% [40 Votes]

7.02.xx
7.02.xx
80% [400 Votes]

Votes: 497
You must login to vote.
Started: 26/03/2012 11:58

Polls Archive
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Connect via Facebook
Connect via Facebook
Our Coders
Shoutbox
You must login to post a message.

18-05-2013 10:01
Can I link a panel to another subdomain? If so how? openside() echo ??? "http://xxxxx/infus
ions/panel/panel.p
hp" closeside()

18-05-2013 01:20

18-05-2013 01:19

18-05-2013 01:18

18-05-2013 00:49

18-05-2013 00:48

18-05-2013 00:21

16-05-2013 22:09
monclermoncler

16-05-2013 22:08
bottes uggbottes ugg Cheers!

16-05-2013 22:07
<a href="http://www.bo
ttesuggpaschersold
e.com/">ugg pas cher</a>ugg pas cher Cheers!

Shoutbox Archive
In memoriam

Nick Jones
1973-2011

Sponsors
Articles Hierarchy
v7 | Custom MySQL error messages
This guide will show you how to make custom error messages in PHP-Fusion, to let the user know what's wrong (instead of the MySQL error-codes)

This is my first How-To, so I'm not sure if I'm very clear.

This is especially handy if you NEED a certain image to display or just want a more user friendly error message.

This How-To was written based on Version 7 codes, any other version of PHP-Fusion may not work.


1: Make a backup of maincore.php, name it whatever you want. you can use this incase anything should go wrong.

2: open the original maincore.php (in notepad, i recommend notepad++ though)

3: search for line 18: if (eregi("maincore.php", $_SERVER['PHP_SELF'])) { die(); }

4: under that add $custerr="some nice error code here";
(line 19)

it should now look like this

if (eregi("maincore.php", $_SERVER['PHP_SELF'])) { die(); }
$custerr="some nice error code here";

5: go to line 106, the following code will start from there

// MySQL database functions
function dbquery($query) {
$result = @mysql_query($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}

function dbcount($field, $table, $conditions = "") {
$cond = ($conditions ? " WHERE ".$conditions : "");
$result = @mysql_query("SELECT Count".$field." FROM ".$table.$cond);
if (!$result) {
echo mysql_error();
return false;
} else {
$rows = mysql_result($result, 0);
return $rows;
}
}

function dbresult($query, $row) {
$result = @mysql_result($query, $row);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}

function dbrows($query) {
$result = @mysql_num_rows($query);
return $result;
}

function dbarray($query) {
$result = @mysql_fetch_assoc($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}

function dbarraynum($query) {
$result = @mysql_fetch_row($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}

function dbconnect($db_host, $db_user, $db_pass, $db_name) {
$db_connect = @mysql_connect($db_host, $db_user, $db_pass);
$db_select = @mysql_select_db($db_name);
if (!$db_connect) {
die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Unable to establish connection to MySQL</b><br />".mysql_errno()." : ".mysql_error()."</div>");
} elseif (!$db_select) {
die("<div style='font-family:Verdana;font-size:11px;text-align:center;'><b>Unable to select MySQL database</b><br />".mysql_errno()." : ".mysql_error()."</div>");
}
}

6: replace above with:

// MySQL database functions
function dbquery($query) {
$result = @mysql_query($query);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbcount($field, $table, $conditions = "") {
$cond = ($conditions ? " WHERE ".$conditions : "");
$result = @mysql_query("SELECT Count".$field." FROM ".$table.$cond);
if (!$result) {
echo $custerr;
return false;
} else {
$rows = mysql_result($result, 0);
return $rows;
}
}

function dbresult($query, $row) {
$result = @mysql_result($query, $row);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbrows($query) {
$result = @mysql_num_rows($query);
return $result;
}

function dbarray($query) {
$result = @mysql_fetch_assoc($query);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbarraynum($query) {
$result = @mysql_fetch_row($query);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbconnect($db_host, $db_user, $db_pass, $db_name) {
$db_connect = @mysql_connect($db_host, $db_user, $db_pass);
$db_select = @mysql_select_db($db_name);
if (!$db_connect) {
die("$custerr");
} elseif (!$db_select) {
die("$custerr");
}
}

7: Save file and re-upload
8: If anything went wrong, restore from the backup you made in step 1.

Hint:
you can also make multiple error message for each instance, for example:

if (eregi("maincore.php", $_SERVER['PHP_SELF'])) { die(); }
$custerr="query error";
$custerr2="dbcount function error";


// MySQL database functions
function dbquery($query) {
$result = @mysql_query($query);
if (!$result) {
echo $custerr;
return false;
} else {
return $result;
}
}

function dbcount($field, $table, $conditions = "") {
$cond = ($conditions ? " WHERE ".$conditions : "");
$result = @mysql_query("SELECT Count".$field." FROM ".$table.$cond);
if (!$result) {
echo $custerr2;
return false;
} else {
$rows = mysql_result($result, 0);
return $rows;
}
// rest of mysql functions here


etc :)

Hope you like it, it's a bit simple, but useful :)

Written by Joey van Hummel
10112
alternator on October 11 2009 00:06:06

nice code. this is what i need. sometime web hosting limiting their sql connection and an error always come up with non-user friendly message.

Post Comment
Please Login to Post a Comment.
Ratings
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.