Jump to content

PHP Warning: mysql_affected_rows()


xiaix

Recommended Posts

Error (warning) message received:

PHP Warning:  mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in ...

 

Setup:

 

application.php

<?php
include($_SERVER['DOCUMENT_ROOT'] . "/config/siteConfig.php");
include(SESSION_CLASS);
include(SITE_CLASS);
include(DATABASE_CLASS);

$mySession = new session();
$site = new site();
$db = new database();
$site->dbAccess("myDatabase");
$db->dbConnect("localhost", $site->dbUsr, $site->dbPas, $site->dbDB);
$site->freeDBinfo();


if ((isset($_POST["insertData"])) && ($_POST["insertData"] == "formData"))
{
  $insertSQL = sprintf("INSERT INTO application (First_Name, Last_Name) VALUES (%s, %s)",
		       $db->GetSQLValueString($_POST['FIRST_NAME'], "text"),
		       $db->GetSQLValueString($_POST['LAST_NAME'], "text"));

  $dbQueryResult = $db->dbQuery($insertSQL, $db->dbConID);
}
?>

// Blah blah, some html...

<?php
  if ($db) $db->dbFree();
  if ($db) $db->dbClose();
?>

 

 

database.class.php

<?php
function dbQuery($query, $dbConID)
	{
		$this->thisQuery = mysql_query($query, $dbConID);

		if (!$this->thisQuery)
		{
			die('Invalid query);
		}

		$subStr = strtoupper(substr($query, 0, 4));
		switch($subStr)
		{
			case strstr(trim($subStr), "SEL"):
			case strstr(trim($subStr), "SHO"):
				$this->dbNumRows = mysql_num_rows($this->thisQuery);
				break;
			case strstr(trim($subStr), "INS"):
			case strstr(trim($subStr), "DEL"):
			case strstr(trim($subStr), "REP"):
			case strstr(trim($subStr), "UPD"):
				$this->dbNumRows = mysql_affected_rows($this->thisQuery);
				break;

		}
		return $this->thisQuery;
}
?>

 

 

The query inserts the record, no problem.  I'm just wondering why I'm receiving the warning (as mentioned at the top of this post).

 

If anyone needs to see more code, let me know.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/138545-php-warning-mysql_affected_rows/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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