-1

I have a php class, this is a fragment of him:

<?
class labelUpdater
{
    private static $link = mysql_connect("localhost", "login", "password");
    if (!$link) {
        die('Connection error: ' . mysql_error());
    }
    echo 'Success';
    mysql_close($link);die;
}
?>

When I launch it, I'm getting this:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in /var/www/..../labelUpdater.php on line 6

What I'm doing wrong?

Itay
  • 16,048
  • 2
  • 46
  • 67
Alexey Berezuev
  • 735
  • 8
  • 25

1 Answers1

2

You can't just write code inside a class, you have to enter it into a function.

Also, it's a better practice to use <?php instead of <?.

Further more, notice that the mysql_ extension is deprecated in PHP 5.5. You should use newer and safer extensions such as mysqli_ or pdo.

Itay
  • 16,048
  • 2
  • 46
  • 67