diff --git a/examples/server_side/scripts/custom_data_property.php b/examples/server_side/scripts/custom_data_property.php index 624a7a03..cf94a7b3 100644 --- a/examples/server_side/scripts/custom_data_property.php +++ b/examples/server_side/scripts/custom_data_property.php @@ -29,14 +29,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -124,13 +138,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -139,7 +153,7 @@ SELECT COUNT(".$sIndexColumn.") FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/details_col.php b/examples/server_side/scripts/details_col.php index 3a5a54d0..105b374f 100644 --- a/examples/server_side/scripts/details_col.php +++ b/examples/server_side/scripts/details_col.php @@ -29,14 +29,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -124,13 +138,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -139,7 +153,7 @@ SELECT COUNT(".$sIndexColumn.") FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/filter_col.php b/examples/server_side/scripts/filter_col.php index dd5bca7f..4f37b16a 100644 --- a/examples/server_side/scripts/filter_col.php +++ b/examples/server_side/scripts/filter_col.php @@ -2,11 +2,30 @@ /* MySQL connection */ include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" ); /* ;-) */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + /* + * MySQL connection + */ + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } + + /* Paging */ $sLimit = ""; @@ -65,12 +84,12 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -78,7 +97,7 @@ SELECT COUNT(id) FROM ajax "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/id.php b/examples/server_side/scripts/id.php index 5e1040a7..12d2a24b 100644 --- a/examples/server_side/scripts/id.php +++ b/examples/server_side/scripts/id.php @@ -29,14 +29,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -124,13 +138,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -139,7 +153,7 @@ SELECT COUNT(".$sIndexColumn.") FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/id_jsonp.php b/examples/server_side/scripts/id_jsonp.php index 243b492e..6523518d 100644 --- a/examples/server_side/scripts/id_jsonp.php +++ b/examples/server_side/scripts/id_jsonp.php @@ -29,14 +29,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -124,13 +138,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -139,7 +153,7 @@ SELECT COUNT(".$sIndexColumn.") FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/jsonp.php b/examples/server_side/scripts/jsonp.php index 8fab4df8..71e0ca11 100644 --- a/examples/server_side/scripts/jsonp.php +++ b/examples/server_side/scripts/jsonp.php @@ -29,14 +29,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -124,13 +138,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -139,7 +153,7 @@ SELECT COUNT(".$sIndexColumn.") FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/objects.php b/examples/server_side/scripts/objects.php index 376246c9..0ecb6784 100644 --- a/examples/server_side/scripts/objects.php +++ b/examples/server_side/scripts/objects.php @@ -29,14 +29,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -126,13 +140,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -141,7 +155,7 @@ SELECT COUNT(".$sIndexColumn.") FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/objects_jsonp.php b/examples/server_side/scripts/objects_jsonp.php index 62466b4e..1099d77c 100644 --- a/examples/server_side/scripts/objects_jsonp.php +++ b/examples/server_side/scripts/objects_jsonp.php @@ -29,14 +29,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -126,13 +140,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -141,7 +155,7 @@ SELECT COUNT(".$sIndexColumn.") FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/post.php b/examples/server_side/scripts/post.php index 7e37e364..792f50d7 100644 --- a/examples/server_side/scripts/post.php +++ b/examples/server_side/scripts/post.php @@ -29,14 +29,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -123,13 +137,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -138,7 +152,7 @@ SELECT COUNT(".$sIndexColumn.") FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/scripts/server_processing.php b/examples/server_side/scripts/server_processing.php index 46f7ae77..7af6ff00 100644 --- a/examples/server_side/scripts/server_processing.php +++ b/examples/server_side/scripts/server_processing.php @@ -29,24 +29,37 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); - - + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } + /* * Paging */ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { - $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ". - mysql_real_escape_string( $_GET['iDisplayLength'] ); + $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". + intval( $_GET['iDisplayLength'] ); } @@ -124,13 +137,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -139,7 +152,7 @@ SELECT COUNT(`".$sIndexColumn."`) FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; diff --git a/examples/server_side/server_side.html b/examples/server_side/server_side.html index 2fb98507..a32e547b 100644 --- a/examples/server_side/server_side.html +++ b/examples/server_side/server_side.html @@ -111,14 +111,28 @@ * no need to edit below this line */ + /* + * Local functions + */ + function fatal_error ( $sErrorMessage = '' ) + { + header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' ); + die( $sErrorMessage ); + } + + /* * MySQL connection */ - $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or - die( 'Could not open connection to server' ); - - mysql_select_db( $gaSql['db'], $gaSql['link'] ) or - die( 'Could not select database '. $gaSql['db'] ); + if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) ) + { + fatal_error( 'Could not open connection to server' ); + } + + if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) ) + { + fatal_error( 'Could not select database ' ); + } /* @@ -203,13 +217,13 @@ $sOrder $sLimit "; - $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; - $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; @@ -218,7 +232,7 @@ SELECT COUNT(`".$sIndexColumn."`) FROM $sTable "; - $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); + $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() ); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0];