1

私はphpと、多くの場合関数が変数として定義されていることを理解する上での問題を学び始めました。誰かが私にその背後にある実際の目的と例を説明できますか?

$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.
?>

ご覧$dbのとおり、以下のコードでは使用されておらず、このコードはデータベースに完全に接続して機能します。私がそれをよりよく理解するのを助けるための代替方法は何でしょうか。私はインターネットでそれを検索してきましたが、役立つ答えを見つけることができませんでした。よろしくお願いします。

4

2 に答える 2