| DEFINE ('DB_USER', 'USERNAME'); DEFINE ('DB_PASSWORD', 'PASSWORD'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'DATABASE'); $dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() ); |
| function Post(){ require_once('mysql_connect.php'); $this->table = "informit_ajax"; } |
| function dbConnect(){ DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)); } |
| function get(){ $this->dbConnect(); $query = "SELECT * FROM $this->table ORDER BY id"; $result = mysql_db_query (DB_NAME, $query, LINK); $xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"; $xml .= "<posts>\n"; while($row = mysql_fetch_array($result)) { $xml .= "<post>\n"; $xml .= "<id>" . $row['id'] . "</id>\n"; $xml .= "<date>" . $row['date'] . "</date>\n"; $xml .= "<title><![CDATA[" . $row['title'] . "]]></title>\n"; $xml .= "<description><![CDATA[" . $row['description'] . "]]></description>\n"; $xml .= "</post>\n"; } $xml .= "</posts>"; mysql_close(); header("Content-Type: application/xml; charset=UTF-8"); echo $xml; } |
| function save($id, $title, $description){ $this->dbConnect(); $query = "SELECT * FROM $this->table WHERE id='$id'"; $result = @mysql_query ($query); if (mysql_num_rows($result) > 0) { $query = "UPDATE $this->table SET title='$title', description='$description', date=NOW() WHERE id='$id'"; $result = @mysql_query($query); } else { $query = "INSERT INTO $this->table (title, description, date) VALUES ('$title', '$description', NOW())"; $result = @mysql_query($query); } mysql_close(); $this->get(); } |
| function delete($id){ $this->dbConnect(); $query = "DELETE FROM $this->table WHERE id='$id'"; $result = @mysql_query($query); mysql_close(); $this->get(); } |
| require_once("../classes/Post.class.php"); $post = new Post(); $post->$method($id, $title, $description); |