rabidmachine9
rabidmachine9

Reputation: 7985

php class crash course

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

 ?>

Upvotes: 3

Views: 581

Answers (4)

catchmeifyoutry
catchmeifyoutry

Reputation: 7389

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

Upvotes: 1

webbiedave
webbiedave

Reputation: 48887

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.

Upvotes: 3

subv3rsion
subv3rsion

Reputation: 412

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

Upvotes: 1

GSto
GSto

Reputation: 42380

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.

Upvotes: 6

Related Questions