General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 20th, 2003, 03:32 AM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via Yahoo to fakker
Question $this->dbfield help

hey,

in all my PHP apps, I use the following (sort of) code to get my results...

PHP Code:
 $SQL "SELECT * FROM xx WHERE yy = 'z';";
    
$result = @mysql_query($SQL,$connection) or die("Couldn't execute query 2.");
    if (
$result)
    { 
        while (
$row mysql_fetch_array($result)) {
            
$a $row['a'];
            
$b $row['b'];
            
$c $row['c'];
            
$d $row['d'];
        }
    } 


but since I learnt to use that a few years ago, I have seen people using things like:

PHP Code:
 $sql "SELECT * FROM xx WHERE y = 'z'";
$result mysql_query($sql$this->db); 


I wondered.... what is this method of connecting, and how does it differ from my first example... any suggestions or examples will be much appreciated!!
__________________
Matt 'Fakker' Facer

mattfacer.com

Reply With Quote
  #2  
Old June 20th, 2003, 09:42 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 16
OOP

PHP Code:
class DB
{
    function 
DB()
    {
        
$this->host '';
        
$this->username '';
        
$this->password '';
        
$this->db '';
    }
    
    function 
connect()
    {
        if( 
mysql_connect( <!-- params --> ) )
        {
        }
    }

__________________
-- Jason

Reply With Quote
  #3  
Old June 20th, 2003, 09:53 AM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via Yahoo to fakker
cheers jason!!

another question.... how is that then used?
If I had the following in the db...

- name
- username
- password
- age

if that connection is in another file, say connection.php.... but then in "getuser.php" I wanted to get the username and password.... how do I access the connection?

$this->username

?? thanks!!

Reply With Quote
  #4  
Old June 20th, 2003, 11:41 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 16
well,....keep in mind that what I have shown you is meerly for setting up connectivity to the db.

PHP Code:
class DB
{
    function 
DB()
    {
        
/********************************
        | This is the class contructor.  
        | Since it is the same name as the
        | class, this function will execute
        | when you call the class
        *********************************/
        
$this->host 'localhost';
        
$this->username 'user';
        
$this->password 'pass';
        
$this->db 'mydb';
        
$this->conn_type 'mysql_pconnect';
    }
    
    function 
connect()
    {
        
$this->connection $this->conn_type$this->host$this->username$this->password ) or die( "Connection Error" );
    }



To make this work.

PHP Code:
include_once( "this_code_above.php" ); // Or just paste in every page.
$DB = new DB;
$DB->connect(); 


What you want to do is access your database connection and your sessions at the same time. Check out Jpenn's Session handler, it is very nice. It should give you some ideas on how to manage your db connections.
http://www.cheetah-soft.com/csh/

Last edited by Taelo : June 20th, 2003 at 11:46 AM.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > $this->dbfield help


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap