i started learning php and my problem with understanding that in many cases functions are defined as variables. can anyone explain me what is the actual purpose behind it and example:
$db_name= "testdb";
$table_name= "my_music";
// below we create the connection to the database.
$connection= @mysql_connect("localhost", "myusername", "mypassword") or die(mysql_error());
// below we are gonna define what database to connect.
$db= @mysql_select_db($db_name, $connection) or die(mysql_error());
//below creates the sql statement so it can insert the data into the table.
$sql= "
INSERT INTO $table_name
(format, title, artist_fn, artist_ln, rec_label, my_notes, date_acq)
VALUES
('$format', '$title', '$artist_fn', '$artist_ln', '$rec_label', '$my_notes', '$date_acq')";
//below is the function that holds the result of the query function
$result= @mysql_query($sql, $connection) or die(mysql_error());
// end of the php for inserting data into database.
?>
As you see here $db
is not used in any following codes and this code is perfectly connecting to the database and does the work. what would be the alternative way to help me understand it better. i have been searching it over the internet but could not find any helpful answer
Thanks in advance.