php class crash course

class, oop, php, syntax-error

Solution

your missing the $ on all of your variables in the class. line 9 should look like this:

mysql_connect(&$hostname, &$myname, &$pass) or die("Could not connect!")

also, I don't know why your passing by reference (using the & sign) here, it seems unnecessary.

Problem

I'm going crazy trying to write my first php class; it is supposed to connect me to server and to a database but I'm always getting this error: `Parse error: syntax error, unexpected ',', expecting T_PAAMAYIM_NEKUDOTAYIM in /Applications/XAMPP/xamppfiles/htdocs/classTest/test.php on line 9` Thanks in advance, here is the code: ``` <?php // include 'DBConnect.php'; class DBConnect { function connection($hostname = "localhost", $myname = "root", $pass = ''){ mysql_connect(&hostname, &myname, &pass) or die("Could not connect!"); //Connect to mysql } function choose($dbnam){ mysql_select_db(&dbnam) or die("Couldn't find database!"); //fnd specific db } } $a = new DBConnect(); $connect = $a->connection("localhost", "root"); $a->choose('mydb'); ?> ```

Original source