Backing Up a MySQL database

It is strongly recommended to backup databases at regular intervals and always before an upgrade. Restoring the database from backup is then possible if anything goes wrong.

phpMyAdmin is the usual program to manipulate a MySQL database.

To export tables from a database, login to phpMyAdmin, select the name of the database, choose those tables that corresponds to the related application and check the following options :

  • SQL
  • Structure
  • Add drop table
  • Add auto-increment
  • Enclose table and field names with backquotes
  • Data heading (without ticking the inside boxes)
  • Same as file
  • Zipped compression
  • Export type “insert”

Click GO and save the file to the computer. If you have separate files and folders for images, downloads, media or other attachments, save them with FTP on the computer.

A general rule of thumb is to keep at least three backups of databases and data files and to keep them in different places.

To restore the database, login to phpMyAdmin, select the database to restore, click the import tab, locate the .sql file on the computer, check the SQL radio button and click GO. The import may take a while, at the end a success screen is displayed. In case of separate image and media files, restore them with FTP.

WordPress has an integrated export/import function which is very userfriendly and efficient. It’s possible to change the author of the posts before saving and to import also automatically the attachments.

Today I tried the import and export of blogs with phpMyAdmin and with WordPress with success.

XHTML validation and Javascript : CDATA

With HTML pages on the web you can include the required Javascript betweentags. The W3C validator ignores the Javascript content. The same is not true for XHTML where the code between the script tags is considered to be PCDATA (parsed character data) which is therefore processed by the validator.

The result is a break of the page validation. To fix this problem, one solution is to make the Javascript external to the page. Another solution is to  place the Javascript code within a CDATA tag. However some older web browsers don’t understand the CDATA tag and this breaks the Javascript in those browsers.

If the CDATA tag is commented out, the Javascript code is handled correctly both by newer browsers and by validators and ignored by older browsers and the page is displayed as expected in all cases.

<script type=”text/javascript”>
/* <![CDATA[ */
// content of your Javascript goes here
/* ]]> */
</script>

A guide about this topic has been written by Stephen Chapman on the About.com:Javascript website.

eBay Development : Finding API

These are complimentary informations to my first post about eBay Development and are focused on the new Finding API. The homepage of the eBay Developers Program is http://developer.ebay.com/.

eBay provides a set of keys (DEVID, AppID, CertID) for the sandbox and for production. These keys are registrated at the personal eBay developer account webpage. Developer centers are available for Windows, Java, PHP, Javascript and Flash. There are different API’s available for selling, buying, research and monitoring :

  • Finding
  • Shopping
  • Merchandising
  • Feedback
  • Trading
  • Large merchants
  • Client alerts
  • Platform notifications
  • Research

There are call limits per day for the different API’s. For higher call limits, applications need to complete a compatible application check process.

eBay Finding API enables applications to search for eBay items using eBay’s next generation Finding Platform. Today I replaced the eBay shopping API by the new Finding API in my applications.

The supported functions for the Finding API are :

  • getSearchKeywordsRecommendation: Get recommended keywords for search
  • findItemsByKeywords: Search items by keywords
  • findItemsByCategory: Search items in a category
  • findItemsAdvanced: Advanced search capabilities
  • findItemsByProduct: Search items by a product identifier
  • findItemsIneBayStores: Search items in stores
  • getHistograms: Get category and domain meta data

The function findItemsAdvanced enables searching for items on eBay by category (using categoryId), by keywords (using keywords), or a combination of the two. By setting the descriptionSearch field to true, the keyword queries also search the item descriptions, in addition to searching through the item title and subtitles. Another interesting finction is getHistograms which returns category and/or aspect histogram information for the eBay category ID you specify.

There are different possibilities to obtain the list of categories ID’s for a specified eBay website (php program,  special API, …). A simple solution is to access the storelist online at the eBay website with the url http://listings.ebay.xx, for instance:

Other needed informations to use the eBay API efficiently are the Global ID, a unique identifier for combinations of site, language, and territory. The list of Global ID’s is available on the eBay developer website.

The keywords field is the basis for item searches. The value specified in the keywords field can contain one or more keywords and combinations of wildcard characters. The words “and” and “or” are treated like any other word.  You can use AND or OR logic by including certain modifiers. The complete list of modifiers and wildcards for searching by keywords is available at the eBay developer website.

A search can be refined with item, aspect and domain filters. Filters provide better control over the search results by narrowing the range of items returned. Domains are a buy-side grouping of items, such as women’s dresses. A domain can span many eBay categories and some categories may be included in more than one domain. Aspects are item characteristics, such as brand, product type, size, which are shared by certain types of items. For example, for Shoes, aspects include Style, Color, and Shoe Size. For Digital Cameras, aspects include Product Type, Brand, Megapixels, and Optical Zoom.

In addition to filters, you can specify certain properties to control the way data is returned. These do not control which data is returned, but rather how it is sorted and the volume of the response. The applicable sort values are available at the eBay developer website.

Use paginationInput and its child elements to break the items matching the search criteria down into smaller subsets, or “pages” of data. The paginationInput.entriesPerPage field specifies the maximum number of items to return for any given request. The paginationInput.pageNumber field specifies which “page” of data to return in the current call. The maximum value for paginationInput.entriesPerPage is 100, this is also the default value.

To include additional informations in the search results as the default values, the outputSelector fields can be used. To earn money from eBay for driving trafic to their website, affiliate-related fields, which are included in a call request using the affiliate container, enable the tracking of user activity. Commissions are generated when users do qualifying actions, such as bid, buy, or register. The affiliate container has the following fields: networkId, trackingId, and customId.

There is no difference between uppercase or lowercase characters in the keywords. Special caracters as é, è, à, ü etc are however not recognised.

SWFObject

SWFObject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file. The actual version of the open-source project is 2.2. The work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. The authors of SWFObject are Geoff Stearns, late Michael Williams and Bobby van der Sluis.

SWFObject offers:

  • two optimized Flash Player embed methods; a markup based approach and a method that relies on JavaScript
  • a JavaScript API that aims to provide a complete tool set for embedding SWF files and retrieving Flash Player related information
  • only one small JavaScript file (10Kb / GZIPed: 3.9Kb)
  • replacement of SWFObject 1.5, UFO and the Adobe Flash Player Detection Kit
  • unification of all existing Flash Player embed methods and provision of a new standard for embedding Adobe Flash Player content
  • detection of the Flash Player version and determination whether Flash content or alternative content should be shown, to avoid that outdated Flash plug-ins break Flash content
  • functionality to revert to alternative content in case of an outdated plug-in by means of a DOM manipulation (Note: if no Flash plug-in is installed the HTML object element automatically falls back to its nested alternative content)
  • the option to use Adobe Express Install to download the latest Flash Player

SWFObject 2 offers two distinct methods to embed Flash Player content:

1. The static publishing method embeds both Flash content and alternative content using standards compliant markup, and uses JavaScript to resolve the issues that markup alone cannot solve
2. The dynamic publishing method is based on marked up alternative content and uses JavaScript to replace this content with Flash content if the minimal Flash Player version is installed and enough JavaScript support is available.

Both methods have advantages. The SWFObject library consists of one external JavaScript file. SWFObject will be executed as soon as it is read and will perform all DOM manipulations as soon as the DOM is loaded – for all browsers that support this, like IE, Firefox, Safari and Opera 9+ – or otherwise as soon as the onload event fires.

An online HTML and javascript generator is provided to create the right code for an swf object. A tutorial how to use SWFObject is available on the Adobe website. The following link leads to a webpage with a script indicating the installed Flash version.

Delete wordpress post revisions

To delete and remove all existing post revisions entries and rows from WordPress database posts table, login to phpMyAdmin, select the appropriate WordPress database and then issue the following command :

DELETE FROM wp_posts WHERE post_type = ‘revision’;

To turn off and disable automatic post revisions, simply add the following line of code to wp-config.php file located in the root or home directory of WordPress blog:

define(’WP_POST_REVISIONS’, false);

PHP foreach loop

A foreach loop can be used in PHP  with an array instead of a counter. If an array contains 5 pieces of data, then the foreach loop would execute 5 times.

A foreach loop is phrased like this: foreach (array as value) { what to do; }

Here is an example of a foreach loop:

<?php
$a = array(1, 2, 3, 4, 5);
foreach ($a as $b)
{
echo $b;
echo (‘<br/>’);
}
?>

Authentification

Authentication is a process for identifying and verifying who is sending a request. The following list shows a simplified version of an authentication process :

  • The sender obtains the necessary credential.
  • The sender sends a request with the credential to the recipient.
  • The recipient uses the credential to verify the sender truly sent the request.
  • If yes, the recipient processes the request. If no, the recipient rejects the request and responds accordingly.

Amazon® Product Advertising API with signed requests

By August 15, 2009, all calls to the Amazon® Product Advertising API must be signed to authenticate the request. Ulrich Mierendorff developped a simple function in PHP that lets you make authenticated requests with only a few lines of code. He is also the author of “Antialiased filled Arcs/Ellipses” for PHP and of the rounded css boxes.

Other PHP example for Amazon signed requests have been posted by Mark on his blog “Every Good Path” and by Horacix on his blog “Inside Things“.

Amazon’s guidelines for signing requests are available on the AWS website.

The following error messages are sent:

  • the timestamp is old : Request has expired

Meta tags and web search

Meta tags provide information to all sorts of clients, such as browsers and search engines. A useful contribution how Google interprets meta tags has been published on the Webmaster Central Blog (Official news on crawling and indexing sites for the Google index). Another contribution provides hints how to create good descriptions.

A script how to create dynamic META descriptions for a WordPress Blog has been published by Darren Pangan on his blog. A useful contribution about the meta description tag has been published by Christopher Heng. A script how to extract and display meta tags is available at stackoverflow website.

The standalone XML-sitemap generator provides an option to display the meta description tags in the custom sitemap list.

Destroy, delete, unlink files : access denied

Sometimes there are files on a hosted server which can not be deleted by FTP even if you are logged in as the domain administrator. This happens for example when you upload a file using PHP. These files will be marked as being owned by the Apache (or Fast-CGI) user. So when you log into the FTP or the Plesk or Confixx desktop with your own user id, you can’t delete or change the files PHP has uploaded as they are owned by another user.

The only way to delete or change these files is to do it by a PHP script. In PHP you delete files by calling the unlink function.

To delete the file test.txt we simply run a PHP script that is located in the same directory.

<?php
$myFile = “test.txt”;
unlink($myFile);
?>

I had this problem a few days ago when I tried to delete an old wordpress installation on a server and it was not possible to delete the uploads folder cretaed by the wordpress application.