Revision: 2597
Updated Code
at March 13, 2007 11:02 by purpleraison
Updated Code
<?php
//created by me...
class apple {
// connect to, and select the database
private function connectDB(){
$dbconnect = mysql_connect('localhost', 'root','', 'form')
or die('no connection');
mysql_select_db("form");
echo 'connected';
}
// get table names
function gettables(){
$this->connectDB();
$query = 'SHOW TABLES from form';
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
for ($i = 0; $i < $num_rows; $i++) {
echo "<p>Table: ", mysql_tablename($result, $i), "</p>\n";
}
}
// list articles
function goober() {
$this->connectDB();
$result = mysql_query("SELECT * FROM article");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
print("<h2>".$row['title']."</h2>");
print($row["content"]."<br />");
}
}
// insert article
function insertArticle(){
$sql = mysql_query("INSERT INTO article (title, content) VALUES('class1', 'tree1')")
or die;
}
// disconnect
function disconnectDB(){
mysql_close();
}
}
$art= new apple(); // instantiate the class
$art->goober(); //retrieves articles and displays them
//$art->insertArticle();
$art->disconnectDB();
?>
Revision: 2596
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 13, 2007 10:59 by purpleraison
Initial Code
<?php
//include('connection.php');
class apple {
// connect to, and select the database
private function connectDB(){
$dbconnect = mysql_connect('localhost', 'root','', 'form')
or die('no connection');
mysql_select_db("form");
echo 'connected';
}
// get table names
function gettables(){
$this->connectDB();
$query = 'SHOW TABLES from form';
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
for ($i = 0; $i < $num_rows; $i++) {
echo "<p>Table: ", mysql_tablename($result, $i), "</p>\n";
}
}
// list articles
function goober() {
$this->connectDB();
$result = mysql_query("SELECT * FROM article");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
print("<h2>".$row['title']."</h2>");
print($row["content"]."<br />");
}
}
// insert article
function insertArticle(){
$sql = mysql_query("INSERT INTO article (title, content) VALUES('class1', 'tree1')")
or die;
}
// disconnect
function disconnectDB(){
mysql_close();
}
}
$art= new apple(); // instantiate the class
$art->goober(); //retrieves articles and displays them
//$art->insertArticle();
$art->disconnectDB();
?>
Initial URL
Initial Description
will change to be more specific to what i want l8ter. Just basic at the moment.
Initial Title
connect, retrieve, insert, disconnect class
Initial Tags
Initial Language
PHP