php with two class
Posted
by lolalola
on Stack Overflow
See other posts from Stack Overflow
or by lolalola
Published on 2010-05-27T22:18:27Z
Indexed on
2010/05/27
22:21 UTC
Read the original article
Hit count: 257
php
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");
?>
© Stack Overflow or respective owner