List Info

Thread: note 78036 added to function.mysql-fetch-object




note 78036 added to function.mysql-fetch-object
user name
2007-09-25 00:56:58
If you have a class that represents itself in a database you
can use this function to get the properties.

class MyClass {

  public $name;
  public $language;

  function load($id) {

    $query = mysql_query("SELECT name, language FROM
myTable WHERE id = $id");
    $result = mysql_fetch_object($query, get_class($this));

    foreach(get_object_vars($result) as $var => $value)
$this->$var = $value;
  }

}

$a = new MyClass();
$a->load(1);
----
Server IP: 129.16.214.50
Probable Submitter: 195.178.169.226
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-ob
ject.php
Edit        -- https://master
.php.net/note/edit/78036
Del: integrated  -- h
ttps://master.php.net/note/delete/78036/integrated
Del: useless     -- http
s://master.php.net/note/delete/78036/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/78036/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/78036/spam
Del: non-english -- 
https://master.php.net/note/delete/78036/non-english
Del: in docs     -- http
s://master.php.net/note/delete/78036/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78036
Reject      -- https://mast
er.php.net/note/reject/78036
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )