Jump to content

warning message problem


zsxdcfv21

Recommended Posts

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 ()
{
[b]$numRows = mysql_num_rows( $this->resultResource );[/b]
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.