views:

102

answers:

4

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');

 ?>
+1  A: 

You are missing the $ after the & signs, e.g. &$hostname. Same problem at the mysql_select_db line, by the way.

catchmeifyoutry
+5  A: 

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.

GSto
Definitely unnecessary and deprecated.
webbiedave
Thanks, I didn't wanna pass by reference I just confused the symbols, stupid mistake...
rabidmachine9
+1  A: 

The error 'T_PAAMAYIM_NEKUDOTAYIM' translates to mean "::", double colon). You're just missing the '$' in your variables, mentioned above.

subv3rsion
+2  A: 

To add to the others, try and go with PDO. mysql_* functions are old school at this point. Also, you're assigning the call to connection to a variable even though the connection function never returns anything.

webbiedave
Agreed. Go with PDO. It ships with PHP 5.1 and higher. http://www.php.net/manual/en/ref.pdo-mysql.php
subv3rsion