12Hannibal12 12Hannibal12 - 1 year ago 75
PHP Question

How to execute public functions in PHP?

I've got a file connect.php.

public static function connect() {
$file= file('data.txt');
$hostname = rtrim($file[1]);
$dbname = rtrim($file[4]);
$username = rtrim($file[7]);
$password = rtrim($file[10]);
mysql_connect($hostname, $username, $password) or DIE('Connection to host isailed, perhaps the service is down!');
mysql_select_db($dbname) or DIE('Database name is not available!');

How can I access this function in other .php files?


doesn't work.

Answer Source

That's because it's not possible. You have to access the code in order for it to work. If you want THIS function available on another page then:

<?php include 'connect.php' ?>

With that, you can make your function call on that page and it will work.

That's pretty much it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download