Jump to content


Photo

warning message problem


  • Please log in to reply
2 replies to this topic

#1 zsxdcfv21

zsxdcfv21
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 30 August 2006 - 02:53 PM

got a warning message on line 132. line 132 is in bold letters

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/mywebsitehere.com/httpdocs/lib.classes/class.MySQL.php on line 132

<?php

class MySQL {

var $hostname, $username, $password, $dbName, $dbCn, $sqlQuery, $resultResource;

function MySQL( $hostname = 'xxxxx', $username = xxxxx, $password = xxxxx, $dbName = xxxxx)
{
/***
* this class will check for constants that it requires.. if params were not supplied?
*/

// init variables
$this->hostname = $hostname;
$this->username = $username;
$this->password = $password;
$this->dbName = $dbName;
$this->sqlQuery = '';
$this->resultResource = NULL;

// connect to db
$this->dbCn = mysql_connect($this->hostname, $this->username, $this->password)
or $this->error();

// select db
mysql_select_db($this->dbName, $this->dbCn)
or $this->error();
}


function error ()
{
if ( ! class_exists('NiceMail') ) require('class.NiceMail.php');
$mail = new NiceMail('xxxxxxx', 'xxxxxx@xxxxx.com');
$mail->setSubject('Error in ' . $_SERVER["SCRIPT_NAME"] );
$mail->setRecipient('MySQL', 'xxxxxx@xxxxx.com');
$error =  "[MySQL Error!!!]\nErrorNo:";
$error .= mysql_errno() . "\nError:" . mysql_error() . "\n";
$this->password = 'Intentionally removed.';
ob_start();
var_dump( $this );
$error .= ob_get_contents();
ob_end_clean();
$mail->setBody($error);
$mail->sendMail();
require('func.error.php');
sendAlert('Globals Dump for MySQL wrapper.');

exit();
}


function setQuery ( $queryString )
{
// appends to query!
$this->sqlQuery .= $queryString;
}


function execute ( $queryString = NULL )
{
// execute the query
if ($queryString !== NULL) {
$this->setQuery($queryString);
}
$this->resultResource = mysql_query( $this->sqlQuery )
or $this->error();
// query was successful if this far, reset query
$this->sqlQuery = '';
}


function executeOrDie ( $queryString = NULL )
{
// if no rows return... terminate
if ($queryString !== NULL)
{
$this->setQuery($queryString);
}

$this->execute();

if ( ! $this->resultHasRows() )
{
require('func.error.php');
sendAlert('Execute or Die Died!');
exit();
}

return mysql_fetch_object($this->resultResource);
}


function executeQuietly ( $queryString = NULL )
{
// execute the query but don't bounce an error
if ($queryString !== NULL) {
$this->setQuery($queryString);
}
$this->resultResource = mysql_query( $this->sqlQuery );
$this->sqlQuery = '';
}


function executeQuickly ( $queryString )
{
// executes a single string (and appends old sql query) and returns an object..!
$this->setQuery( $queryString );
$this->execute();
return $this->getObject();
}


function isError ()
{
if ( $this->resultResource === FALSE ) {
return TRUE;
} else {
return FALSE;
}
}


function getErrorNum ()
{
return mysql_errno( $this->dbCn );
}


function resultHasRows ()
{
$numRows = mysql_num_rows( $this->resultResource );
if ($numRows) return true;
return false;
}


function getObject ()
{
// fetch a mysql object if any left
if ( $object = mysql_fetch_object($this->resultResource) ) {
// return the object
return $object;
} else {
// return false and free resource
mysql_free_result( $this->resultResource );
return false;
}
}

function getLastInsertId ()
{
$obj = $this->executeQuickly('SELECT LAST_INSERT_ID() LastInsertID');
return (int) $obj->LastInsertID;
}

function getNumRows ()
{
return mysql_num_rows( $this->resultResource );
}

}

?>


whats wrong with my script? is it because of resultResource?



#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 August 2006 - 03:29 PM

More than likely your query is failing... you should try some debugging to locate the actual cause.

#3 zsxdcfv21

zsxdcfv21
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 30 August 2006 - 03:38 PM

thats the problem.... theres no errors except warning messages....can you pinpoint to me wc do you think is the problem?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users