How do I connect to another database on another server from my PHP script?

A connection is made to a database with the usual statement:

mysql_connect(‘localhost’,’USERNAME’,’PASSWORD’);

Where ‘localhost’ is the database on the same web server as the PHP script.

If you want to connect to a database to another web server you would replace localhost’ to that of the IP address of the web server.

The web server where a database resides can be found by moving your mouse over the “Go” link for the Temp Web Address or clicking the link so the IP is displayed in the browser address bar, within the Web Hosting Plus control panel.

What file extensions can run PHP?

PHP will run all files with the following extensions by default:-

.php
.php3
.php4
.php5

.php4 files will run under PHP4, .php5 files will run under PHP5 by default. .php files will run under the default PHP version (5).

What are the correct file permissions for a PHP file?

As a general rule, the permissions of a PHP file should take one of two sets of values, either 644 or 600.

644 – A PHP file needs to be world readable if it is to be called via your web browser (meaning it is being processed by Apache). Do not include important passwords or secret keys in world-accessible files, as this opens your site up for those with malicious intent.

600 – For include files, typically containing unique keys or passwords (e.g. MySQL credentials, PayPal API Keys). If a PHP file is not accessed directly via your web browser (only referenced via other PHP files), use these permissions.

Why isn’t my custom php.ini working?

There are a few common reasons why custom php.ini files won’t work.

  • Check the file name
    Often if you’re saving it in Windows – for example with Notepad – the file may have been accidentally named “php.ini.txt”. Please ensure this isn’t the case.
  • Is the file in the script directory?
    Make sure the php.ini wasn’t placed in a subfolder, as it will only take affect for that folder and subfolders.

What is PHP?

Self-referentially short for PHP: Hypertext Preprocessor, an open source, server-side, HTML embedded scripting language used to create dynamic Web pages. In an HTML document, PHP script (similar syntax to that of Perl or C) is enclosed within special PHP tags.

Because PHP is embedded within tags, the author can jump between HTML and PHP (similar to ASP and Cold Fusion) instead of having to rely on heavy amounts of code to output HTML. And, because PHP is executed on the server, the client cannot view the PHP code. PHP can perform any task that any CGI program can do, but its strength lies in its compatibility with many types of databases.

PHP is fully supported on all hosting accounts with Web Hosting Plus. For more information about PHP, see the website at: www.php.net