TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 11-14-2007, 05:17 PM   #1 (permalink)
The Contributor
Upcoming Programmer 
 
meshi's Avatar
 
Join Date: Oct 2007
Posts: 44
Thanks: 0
meshi is on a distinguished road
Smile connect database using oop

my head.php

PHP Code:
<?php
 
class mysql {

  function 
Connect($host$name$pass$db){

  
$connection mysql_connect("$host",
  
"$name",
  
"$pass");
  
mysql_select_db("$db"$connection);

  }
//ends the connection function

  
function Close(){

  
mysql_close($this->connection);

  }
//ends the close function

  

  
function FetchArray($query){
  
$rows mysql_fetch_array($query);
  return 
$rows;
  }

  function 
FetchNum($query){
  
$num mysql_num_rows($query);
  return 
$num;
  }

  function 
Query($sql){
  
$query mysql_query($sql) or die(mysql_error());
  return 
$query;
  }
//ends the query function

  
}//ends the class

?>
my test.php

PHP Code:
<?php
include("head.php");

  
$DB = new mysql();

  
$host "localhost";
  
$name "username";
  
$pass "password";
  
$db "database";

  
$connection $DB->Connect($host$name$pass$db);

  
//define an SQL statement and execute it
  
$sql "SELECT username FROM users";
  
$query $DB->Query($sql);

  
//output all rows from the statement
  
while($row $DB->FetchArray($query)){
  echo 
"<b>Username: $row[username]<b><br \>";
  
  }

  
//find the number of rows
  
$num $DB->FetchNum($query);
  echo 
"Number of rows: $num";

  
//close the connection
  
$DB->Close();

?>
it displays correct but there is a warning below..its stated :
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /web/head.php on line 15
why is it myql_close() seem not functioning.im a newbie of OOP..and im tried to connect to database using OOP.just practicing
meshi is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:36 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design