Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
Re: [PHP] OOB problem, super stumped.
Old
  (#1)
Jim Lucas
Guest
 
Posts: n/a
Default Re: [PHP] OOB problem, super stumped. - 06-02-2007, 08:55 PM

Brian Seymour wrote:
> I am super stumped. This works fine separately but when I put everything
> together it breaks. I has an authenticate cl*** and a sql cl***. However I
> always get the same error.
>
>
>
> SQL cl***.
>
> <?php
>
>
>
> cl*** SQL {
>
> public $host;
>
> public $user;
>
> public $p***;
>
> public $conx;
>
> public $db;
>
> public $dbname;
>
> public $query;
>
> public $result;
>
> public $fetchedArray;
>
> public $nRows;
>
>
>
> public function __construct($host,$user,$p***,$dbname = null){
>
> $this->host=$host;
>
> $this->user=$user;
>
> $this->p***=$p***;
>
> $this->conx=$this->connection($host,$user,$p***);
>
> if (!is_null($dbname)){ $this->selectDb($dbname); }
>
> }
>
>
>
> final public function connection($host,$user,$p***){
>
> $this->conx=mysql_connect($host,$user,$p***) or
> die(mysql_error());
>
> }
>
>
>
> final public function selectDb($db){
>
> $this->db=mysql_select_db($db);
>
> }
>
>
>
> final public function query($query){
>
> $this->result=mysql_query($query, $this->conx);
>
> echo mysql_error();
>
> echo $query;
>
> return $this->result;
>
> }
>
>
>
> final public function fetchArray($query){
>
> $this->result=$this->query($query);
>
>
> $this->fetchedArray=mysql_fetch_array($this->result,MYSQL_***OC);
>
> return $this->fetchedArray;
>
> }
>
>
>
> final public function makeArray($query){
>
> $this->curArray=mysql_fetch_array($query,MYSQL_***OC);
>
> return $this->curArray;
>
> }
>
>
>
> final public function numRows($result)
>
> {
>
> $this->nRows=mysql_num_rows($result);
>
> return $this->nRows;
>
> }
>
>
>
> public function __destruct(){
>
> if (isset($this->connection)){
> mysql_close($this->connection); }
>
> }
>
> }
>
> ?>
>
>
>
> Authenticate cl***
>
>
>
> <?php
>
>
>
> cl*** Authentication extends SQL {
>
> public $errorMsg;
>
>
>
> public function __construct(){echo "Auth constructed";}


You didn't call the __construct() method of your parent.

The above code, should be like this

public function __construct($host,$user,$p***,$dbname = null) {
parent::__construct($host,$user,$p***,$dbname);
echo "Auth constructed";
}

You were forgetting to call to the parent and have it initialize the DB
connection.

In the second part, the $auth->verifyCreds() call, it didn't create a
valid db connection to p*** as the second arg to the mysql_query() call.

And by not p***ing the $this->conx as the second arg, you are telling it
to "use the most recently opened mysql connection.

Hope this clears up why it was failing on the latter mysql_query() calls.


>
>
>
> final public function verifyCreds ($user, $p***, $table)
>
> {
>
> $result = $this->query("SELECT * FROM $table where
> $user='$p***'");
>
>
>
> if ($this->numRows($this->result) == 0)
>
> {
>
> $this->errorMsg = "Incorrect Username/P***word
> Combo";
>
> return false;
>
> }
>
> else
>
> {
>
> // debugging lines \/
>
> echo "login good!";
>
> // debugging lines /\
>
> return true;
>
> }
>
>
>
> }
>
>
>
> public function __destruct(){}
>
> }
>
> ?>
>
>
>
> Normal page.
>
> <?php
>
>
>
>
>
> /************************************************** **********
>
> * common.php
>
> *
>
> * project: Renegades Revenge
>
> * programmer: Brian Seymour
>
> ************************************************** **********/
>
>
>
> // autoload cl***es
>
> function __autoload($cl***_name) {
>
> require_once 'includes/cl***es/cl***_' . strtolower($cl***_name)
> . '.php';
>
> }
>
>
>
> // initialize Renegades Revenge database
>
> $database = new SQL($host,$user,$p***,"aerocor_renegade");
>
>
>
> // login
>
> if (isset($_GET['login']))
>
> {
>
> $auth = new
> Authentication($host,$user,$p***,"aerocor_renegade ");
>
> if
> ($auth->verifyCreds($_POST['username'],$_POST['p***word'],"players"))
>
> {
>
> echo "logged in good!";
>
> }
>
> }
>
>
>
> ?>
>
>
>
> The form is just 2 fields. Username and p***word. I get this error.
>
>
>
> Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource
> in /home/aerocor/public_html/rr/includes/cl***es/cl***_sql.php on line 52
> Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
> resource in /home/aerocor/public_html/rr/includes/cl***es/cl***_sql.php on
> line 71
>
>
>
> I put some simple query and display code in the constructor for the SQL
> cl*** and it outputted from the database with no problem, that's whats
> weird.
>
>
>
> Any help would be great, thanks.
>
>
>
> Brian
>
>



--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Unknown
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

RE: [PHP] OOB problem, super stumped.
Old
  (#2)
Brian Seymour
Guest
 
Posts: n/a
Default RE: [PHP] OOB problem, super stumped. - 06-02-2007, 08:56 PM

Jim,
I put the link identifier back and made your recommended changes and now
everything works perfect. Can't thank you enough.

Is the reason you have to call the parents __construct() method because the
open mysql connection only exists within the scope of the object it was
created in, unless specified otherwise(calling parents constructor)?

Brian Seymour
AeroCoreProductions
http://www.aerocore.net/

-----Original Message-----
From: Jim Lucas [private.php?do=newpm&u=]
Sent: Wednesday, May 30, 2007 12:02 AM
To: Brian Seymour
Cc: 'php php'
Subject: Re: [PHP] OOB problem, super stumped.

You didn't call the __construct() method of your parent.

The above code, should be like this

public function __construct($host,$user,$p***,$dbname = null) {
parent::__construct($host,$user,$p***,$dbname);
echo "Auth constructed";
}

You were forgetting to call to the parent and have it initialize the DB
connection.

In the second part, the $auth->verifyCreds() call, it didn't create a
valid db connection to p*** as the second arg to the mysql_query() call.

And by not p***ing the $this->conx as the second arg, you are telling it
to "use the most recently opened mysql connection.

Hope this clears up why it was failing on the latter mysql_query() calls.
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] OOB problem, super stumped.
Old
  (#3)
Jim Lucas
Guest
 
Posts: n/a
Default Re: [PHP] OOB problem, super stumped. - 06-02-2007, 08:56 PM

Brian Seymour wrote:
> Jim,
> I put the link identifier back and made your recommended changes and now
> everything works perfect. Can't thank you enough.
>
> Is the reason you have to call the parents __construct() method because the
> open mysql connection only exists within the scope of the object it was
> created in, unless specified otherwise(calling parents constructor)?

no, you are looking at three different scopes here.

One is the mysql_* function in general. The resource $link_identifier is completely optional.

Read the parameters section and link_identifier section

http://us2.php.net/mysql_query

Now, since you are dealing with two different cl***es, SQL and Authentication, you are deal with yet
another two different scope, one for each cl***.

SQL, by itself has a scope that contains your original $this->conx property. It only exists within
your object called $database.

Now, the final scope is within the Authentication object $auth. Since Authentication extends the
SQL cl***es it will inherit a new/different instance of the SQL cl***/object. Now, since it is a
new copy of the SQL $this->conx does not exists. So, to make the SQL cl*** that is being inherit
have the $this->conx property, you have to call the __construct() method for the parent/SQL cl***.

Hope I haven't confused you even more.

Ask away if you have any questions.

>
> Brian Seymour
> AeroCoreProductions
> http://www.aerocore.net/
>
> -----Original Message-----
> From: Jim Lucas [private.php?do=newpm&u=]
> Sent: Wednesday, May 30, 2007 12:02 AM
> To: Brian Seymour
> Cc: 'php php'
> Subject: Re: [PHP] OOB problem, super stumped.
>
> You didn't call the __construct() method of your parent.
>
> The above code, should be like this
>
> public function __construct($host,$user,$p***,$dbname = null) {
> parent::__construct($host,$user,$p***,$dbname);
> echo "Auth constructed";
> }
>
> You were forgetting to call to the parent and have it initialize the DB
> connection.
>
> In the second part, the $auth->verifyCreds() call, it didn't create a
> valid db connection to p*** as the second arg to the mysql_query() call.
>
> And by not p***ing the $this->conx as the second arg, you are telling it
> to "use the most recently opened mysql connection.
>
> Hope this clears up why it was failing on the latter mysql_query() calls.
>



--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Unknown
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
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

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





Contact Us - Forum Care Forums - Archive - Top