php with two class
- by lolalola
Hi Guys,
my sample is good or not?
I have a good connection to the database, or too should be in the class?
Thanks
<?php
mysql_connect('localhost','root','admin');
mysql_select_db('test');
class UserDisplay
{
function getDisplayName()
{
$sql = 'select first_name, last_name, display_name from users where user_id = "3"';
$results = mysql_query($sql);
$row = mysql_fetch_array($results);
$this->user_id = $user_id;
return $this->user_id;
}
}
class UserInsert
function InsertName($name)
{
mysql_query("INSERT INTO Persons (first_name)VALUES ('".$name."')");
}
}
$userD = new UserDisplay();
echo "User known as: " . $userD->getDisplayName() . "\n";
$userI = new UserInsert();
$userI->InsertName("Peter");
?>