Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

OO PHP Help

Name: Anonymous 2009-07-19 8:20

I need some help learning Object Oriented PHP, and I am the type to learn from examples, so I was wondering if one of you kind gentleman could rewrite this file so that is OO.


$data['uname'] = "root";
$data['paswd'] = "";
$data['dhost'] = "localhost";
$data['dbase'] = "content";

function connect()
{
    global $data;

    $connection    = @mysql_connect(
        $data['dhost'],
        $data['uname'],
        $data['paswd']) or die("Error connectiong: " . mysql_error());

    @mysql_select_db($data['dbase'], $connection);
       
    return $connection;

}

function close($connection)
{
    mysql_close($connection);
}

function showAll()
{
    $connection = connect();
   
    $sql = "SELECT * FROM article";
    $result = mysql_query($sql);
   
    if ($result)
    {
        while ($row = mysql_fetch_array($result))
        {
            echo '<a href="/admin/index.php?id='.$row['id'].'">'.$row['title'].'</a> - <a href="/admin/edit.php?id='.$row['id'].'">EDIT</a> - <a href="/admin/admin.php?a=delete&id='.$row['id'].'">DELETE</a><br />';
        }
    }
   
    close($connection);
   
}

function getArticle($id)
{
    $connection = connect();
    $sql = "SELECT * FROM article WHERE id='$id'";
    $result = mysql_query($sql);
   
    if ($result)
    {
        $row = mysql_fetch_assoc($result);
        $articleinfo[] = $row;
    }
   
    return $articleinfo;
    close($connection);
   
}

Name: Anonymous 2009-07-19 17:56

>>10
object n. 1. any Lisp datum.
You're mixing up classes and objects. Classes are useful only when you wish to have an object that contributes to the structure and behavior of a set of objects. Being able to avoid them entirely is a feature.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List