Jump to content

assoc array or objects


drifter

Recommended Posts

Ooh... Very interesting, check this example out.

[code]
#!/usr/bin/php
<?php

    class user {

        function test() {
            echo "this is a test";
        } 

    } 

    mysql_connect('localhost','thorpe','****');
    mysql_select_db('foo');

    $sql = "SELECT id, val FROM bar WHERE val = 'thorpe'";

    if ($result = mysql_query($sql)) {
        if (mysql_num_rows($result) > 0) {
            $obj = mysql_fetch_object($result,'user');
            echo $obj->val; // produces 'thorpe'
        } 
    } else {
        echo mysql_error();
    } 

    $obj->test(); // produces 'this is a test'

?>
[/code]

This basically meens that you can create a class, with methods already in place to manipulate its properties. You can then run a query and use mysql_fetch_object to populate this objects properties. This could come in REAL handy.

Thanks. Ide never even thought about it untill you asked the question.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.