Jump to content

applebiter

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

applebiter's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was wondering if anyone could help me figure out where I am screwing up! I'm trying to write a really simple class that gets a MySQL resource link AND selects the proper database. In a separate definitions file I call the constructor and populate the new object's fileds. Then, in the actual working file, I include the definitions file. The MySQL error tells me that the resource link is invalid, and I don't know why. First, the class: [code]class DataConnection{     var $hostname;     var $username;     var $password;     var $database;     var $datalink;          function setHostname($pV){         $this->hostname = $pV;     }          function getHostname(){         return $this->hostname;     }          function setUsername($pV){         $this->username = $pV;     }          function getUsername(){         return $this->username;     }          function setPassword($pV){         $this->password = $pV;     }          function getPassword(){         return $this->password;     }          function setDatabase($pV){         $this->database = $pV;     }          function getDatabase(){         return $this->database;     }          function setDatalink($pV){         $this->datalink = $pV;     }          function getDatalink(){         return $this->datalink;     }          function DataConnection($pV1,$pV2,$pV3,$pV4){         $this->hostname = $pV1;         $this->username = $pV2;         $this->password = $pV3;         $this->database = $pV4;         $this->datalink = mysql_pconnect($this->hostname,$this->username,$this->password);         if(!$this->datalink){             return 0;         }         else if(!mysql_select_db($this->database,$this->datalink)){             return 0;         }         else return $this->datalink;     }     }[/code] Then, the definitions file (values deleted): [code]include "DataConnection.php"; function getDatalink(){     if($_SERVER['WINDIR']){         $db_link = new DataConnection("","","","");         return $db_link;     }     if(!$_SERVER['WINDIR']){         $db_link = new DataConnection("","","","");         return $db_link;     } }[/code] Finally, part of the working document: [code]require_once('../inc/DataConnection.php'); session_start(); $query_myResult = "SELECT * FROM rickhomepage WHERE pageNumber = 1"; $myResult = mysql_query($query_myResult, $datalink) or die(mysql_error()); $row_myResult = mysql_fetch_assoc($myResult); $totalRows_myResult = mysql_num_rows($myResult);[/code] Any help would be appreciated!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.