PHP class crash rate

I am going crazy trying to write my first php class; it should connect me to the server and to the database, but I always get 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');

 ?>

      

+2


a source to share


4 answers


your missing $ for all 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 you are passing the link (using sign and sign) here, it seems unnecessary.

+6


a source


To add to the rest, try going with PDO. The mysql_ * functions are old school at this point. Also, you are assigning the connection call to a variable, even though the connection function never returns anything.



+3


a source


You are missing $

after signs &

, for example. &$hostname

... Same problem in line mysql_select_db

, by the way.

+1


a source


The error "T_PAAMAYIM_NEKUDOTAYIM" means "::", double colon). You just didn't include "$" in your variables mentioned above.

+1


a source







All Articles