« Previous entry | Next entry » Browse > Snippets

Skip to comments (8) mysql php header with functions
Posted by Erik on Jan 02 2006 @ 13:15  :: 4503 unique visits

I always include this mysql.inc.php file if I want to do some mysql stuff.
It makes the db connection and defines some useful functions.

mysql.inc.php
CODE: PHP
<?
// mysql.inc.php v1.0 by Erik


function mysql_die($str, $q = '') {
  include './mysql.die.tpl';
  die;
}


function mysql_assocs($query) {
  $r = mysql_query($query);

  if ($r === false) {
    mysql_die('database error.', $query);
  }

  for ($arr = array(); $row = mysql_fetch_assoc($r);) {
    array_push($arr, $row);
  }

  mysql_free_result($r);

  return $arr;
}


function mysql_rows($query) {
  $r = mysql_query($query);

  if ($r === false) {
    mysql_die('database error.', $query);
  }

  for ($arr = array(); $row = mysql_fetch_row($r); ) {
    array_push($arr, $row);
  }

  mysql_free_result($r);

  return $arr;
}


function mysql_simple($query) {
  $r = mysql_query($query);

  if ($r === false) {
    mysql_die('database error.', $query);
  }

  for ($arr = array(); $row = mysql_fetch_row($r); ) {
    array_push($arr, $row[0]);
  }

  mysql_free_result($r);

  return $arr;
}


function mysql_do_query($query) {
  $r = mysql_query($query);
 
  if ($r === false) {
    mysql_die('database error.', $query);
  } else {
    return $r;
  }
}


@mysql_connect('localhost', 'username', 'password') or mysql_die('Cannot connect to the database server... Please wait a few seconds and reload this page (F5).');
@mysql_select_db('database') or mysql_die('Cannot select the database.');

?>


mysql.die.tpl
CODE: PHP
<?
// mysql.die.tpl v1.0 by Erik
// This is just a php-template file for mysql_die, not like the other .tpl files
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Database error</title>
  </head>
  <body>
    <h1>ERROR - <?php echo $str; ?></h1>
    <br />
    <?php echo mysql_error(); ?><br />
    <br />
    <?php echo $q; ?>
  </body>
</html>

8 comments posted so far
Add your own »

1. On Jul 11 2007 @ 14:19 guest wrote:

vvvvvvvvvvv

2. On Feb 10 2009 @ 08:51 guest wrote:

dfgdfg

3. On Feb 28 2009 @ 16:05 gabo wrote:

veremos

4. On Mar 18 2009 @ 09:42 guest wrote:

Weaknesses of world of warcraft gold the client-server model used by World of Warcraft have been wow power levelingexploited in order to crash the cluster of servers that wow8goldmake up a realm. Exploits also include characters being able to instantly Cheapest Wow Goldchange location or teleport. The situation became worse when cheap wow goldtrying to coordinate activities across a number of players or guilds on the same realm.World of Warcraft Lead Producer, stated that new realms would be introduced to relieve warhammer gold the burden on existing ones. Existing realms would be upgraded.

Although the game wow gold follows a similar model to others in the genreand was noted for having wow gold cheap many familiar concepts from roleplaying games, the new approaches gold4powerto reduce pauses between game encounters was well liked. At various times, World of Warcraft players have experienced problems with connecting to and logging in to wow gold for salethe game. Sudden server crashes that would force realms offline also occurred.

5. On May 19 2009 @ 09:37 guest wrote:

Find louis vuitton handbag and louis  Louis Vuitton Handbags , louis vuitton wallet and louis vuitton purse items on Louis Vuitton Store Browse a huge selection of LV Handbags Louis Vuitton is luxury gifts, French fashion, the replica Louis Vuitton Store is woman best friend. With Louis Vuitton Discover real Louis Vuitton bags, Vuitton accessories and the latest handbag lines. Join the biggest active Louis Vuitton enthusiast community on the web today

UGGs is a brand that is all about luxury and comfort for everyday life. Only the finest quality materials are used to create UGG Boots. Provide UGG Women Boots,UGG Man Boots,UGG Kids Boots.
UGG Australia is the largest distributor of Grade-A sheepskin.
Find Women's UGGs, Men's UGG Boots, and Kids UGGs on Sale all made with ... UGG Store include Discount UGG  UGG Classic Tall,UGG Classic Short

Louis Vuitton is luxury gifts, French fashion, the replica Louis Vuitton Handbag is woman best friend.Monogram Groom.
Offers Discount Louis Vuitton handbags and Louis Vuitton bags and all other designer handbags,free global fast shipping,low price and top quality.Monogram Jokes,Monogram Suede cheap Louis Vuitton
Louis Vuitton.

Looking For Gucci Shoes ? Gucci Store provide gucci Mens shoes,gucci Womens shoes
Wonderful Gucci shoes sale Gucci men's shoes and Gucci women's shoes at discount Gucci Shoes prices.
cheap gucci Shoes
Gucci Shoes and gucci clothing Spring - Summer 2009, Prada Shoes and prada clothing from the Latest Collection 2009 and Dolce Gabbana Clothing 2009
Gucci Loafers
Gucci Sneakers

UGGs
Louis Vuitton Handbags
Gucci Shoes
Louis Vuitton
UGG Boots
Louis Vuitton Handbags
gucci shoes
Monogram Groom
Discount Louis Vuitton
UGG Boots
Louis Vuitton handbags

7. On Jul 14 2009 @ 04:03 guest wrote:

buy wow gold
my wow power leveling
buy wow gold
good wow power leveling
BUY wow gold
my wow power leveling
CHEAP rs gold
cheap wow power leveling
CHEAPEST lotro gold
MY aion gold
buy wow gold
cheap wow gold
CHEAPEST wow gold

Add a new comment

Name:
Password: (leave empty for anonymous comment)
 
View formatting tags Comment: