What does the $db
variable do and what can I do with it after writing it after the first parameter? I have searched for an answer but your answers are almost always better.
<?php
mysql_connect("localhost", "username", "password");
mysql_select_db("database", $db);
?>
I ask this question because I see people using the $db
tag a lot with representing the database. They do things like for example this: $db->query("SELECT * FROM questions")
or die($db->error);
.
$db
is usually for database connection. It provides connection link to database, identifies the connection and provides database object. When you use mysql_*
functions, you can define last parameter as connection variable. You use it to indentify connection, so multiple mysql connections don't mix up.