PHP Archive
-
Check Magicquotes
Posted on 28th Jul 2010 | No CommentsUsing this script in an include just helps level the playing field…. ;-) <?php if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value;... -
Backup Database with PHP
Posted on 28th Jul 2010 | No CommentsHere’s a great little script that will back-up your database to a zipped .gz file and store it in a folder on your server…. <?php // Set Vars $dbname =... -
Connect To Database With mysqli_connect
Posted on 5th Jul 2010 | No CommentsHere’s another way to connect to the databse: // Connect with username, password, etc... $link = mysqli_connect('localhost', 'userName', 'passWord'); if (!$link){ $error = 'Unable to connect to the database server.';... -
Connect To Database With mysql_connect
Posted on 5th Jul 2010 | No CommentsThere are several methods of connecting to a database, here’s one example: // Set the database access information as constraints DEFINE ('DB_USER', 'userName); DEFINE ('DB_PASSWORD', 'passWord'); DEFINE ('DB_HOST', 'localhost'); ... -
$_SERVER['DOCUMENT_ROOT']
Posted on 29th Jun 2010 | No CommentsIt’s a good idea to use $_SERVER['DOCUMENT_ROOT'] with includes as it makes life easier if moving a site onto a different development server… i.e. <?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; ?> -
htmlspecialchars()
Posted on 16th Jun 2010 | No CommentsUsed to change HTML characters into ‘safer’ versions… i.e. for use in $_GET[], SQL injection, etc… htmlspecialchars($myVariable, ENT_QUOTES, 'utf-8'); ‘&’ (ampersand) becomes ‘&’ ‘”‘ (double quote) becomes ‘"’ when ENT_NOQUOTES is... -
Count Rows / Records
Posted on 13th Apr 2010 | No CommentsSimple enough…. $result = mysql_query('SELECT * FROM table1'); $num_rows = mysql_num_rows($result); $num_rows returns the number of records returned by the query…. -
Find and Replace text in whole MySQL database
Posted on 28th Mar 2010 | No CommentsAnother splendid idea from Mark Jackson (MJ Digital). This loops through the database and replaces a certain string with another… Ideal is a site name has been changed…. Or I...




![$_SERVER['DOCUMENT_ROOT'] It’s a good idea to use $_SERVER['DOCUMENT_ROOT'] with includes as it makes life easier if moving a site onto a different development server… i.e. <?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php'; ?>](http://www.jonmoore.co.uk/wp-content/uploads/2010/06/AbsoluteStockPhoto_38_5582-115x115.jpg)
![htmlspecialchars() Used to change HTML characters into ‘safer’ versions… i.e. for use in $_GET[], SQL injection, etc… htmlspecialchars($myVariable, ENT_QUOTES, 'utf-8'); ‘&’ (ampersand) becomes ‘&’ ‘”‘ (double quote) becomes ‘"’ when ENT_NOQUOTES is...](http://www.jonmoore.co.uk/wp-content/uploads/2010/06/Awesome-view-man-115x115.jpg)

