#35793 [Fbk->Opn]: General error: 2050

From: Date: Sat, 24 Dec 2005 17:30:16 +0000
Subject: #35793 [Fbk->Opn]: General error: 2050
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-90998@lists.php.net to get a copy of this message
 ID:               35793
 User updated by:  deadman_great at mail dot ru
 Reported By:      deadman_great at mail dot ru
-Status:           Feedback
+Status:           Open
 Bug Type:         PDO related
 Operating System: RH Fedora Core 2
 PHP Version:      5.1.1
 New Comment:

OK, without OO:

<?

$pdo = new PDO('mysql:host=localhost;dbname=mydb','login','pass');
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
	
function Query ()
{
	global $pdo;

	$query = 'SELECT created, to_days(from_unixtime(created)) as
day,count(id) as count '.
	'FROM orders '.
	'WHERE partner=:partner '.
	'AND created>=:date '.
	'GROUP BY day';

	$vars = array(':partner'=>9,':date'=>1132797644);

	$stm = $pdo->Prepare($query);
	$stm->Execute($vars);
	return $stm;
}

$result = Query();
foreach ($result as $day)
{
	print_r($day); echo '<hr>';
}

$result = Query();
foreach ($result as $day)
{
	print_r($day); echo '<hr>';
}

$result = Query();
foreach ($result as $day)
{
	print_r($day); echo '<hr>';
}


?>

SQL:

CREATE TABLE orders (
  id int(10) unsigned NOT NULL auto_increment,
  state tinyint(3) unsigned NOT NULL default '0',
  partner int(10) unsigned NOT NULL,
  created int(10) unsigned NOT NULL default '0',
  completed int(10) unsigned default NULL,
  count tinyint(3) unsigned NOT NULL,
  cost float(11,2) unsigned NOT NULL default '0.00',
  zip int(10) unsigned default NULL,
  region varchar(80) default NULL,
  city varchar(120) default NULL,
  street varchar(255) default NULL,
  house varchar(32) default NULL,
  building varchar(32) default NULL,
  apartment varchar(32) default NULL,
  name varchar(255) default NULL,
  surname varchar(255) default NULL,
  patronymic varchar(255) default NULL,
  mail varchar(120) default NULL,
  comments text,
  PRIMARY KEY  (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO orders VALUES
(1,0,9,1134531133,1134931138,2,20,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
INSERT INTO orders VALUES
(2,4,9,1134911133,1134911139,1,10,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
INSERT INTO orders VALUES
(3,1,9,1134811133,1134811137,4,40,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
INSERT INTO orders VALUES
(4,3,9,1134711133,1134711533,1,10,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
INSERT INTO orders VALUES
(5,4,9,1134511131,1134511138,1,10,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
INSERT INTO orders VALUES
(6,1,0,1135521534,NULL,1,10,121231,'test','test','test','12',NULL,NULL,'test','test','test','one@test.com',NULL);
INSERT INTO orders VALUES
(7,0,9,1134522614,NULL,1,10,354354,'test2','test2','test2','12',NULL,NULL,'test2','test2','test2','two@test.com',NULL);


Previous Comments:
------------------------------------------------------------------------

[2005-12-24 17:12:04] tony2001@php.net

Please remove all the unnecessary OO stuff and provide the table
structure (apparently I need it to run your code).

------------------------------------------------------------------------

[2005-12-24 17:06:49] deadman_great at mail dot ru

Sorry for mistaked code. Original code too long. I can write another
quick sample:

<?

class DB
{
	function __construct ()
	{
		$this->pdo = new
PDO('mysql:host=localhost;dbname=mydb','login','pass');
		$this->pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
	}
	
	function Query ()
	{
		$query = 'SELECT created, to_days(from_unixtime(created)) as
day,count(id) as count '.
		'FROM orders '.
		'WHERE partner=:partner '.
		'AND created>=:date '.
		'GROUP BY day';

		$vars = array(':partner'=>9,':date'=>1132797644);

		$stm = $this->pdo->Prepare($query);
		$stm->Execute($vars);
		return $stm;
	}
}

$db = new DB();

// this fetch works
$result = $db->Query();
foreach ($result as $day)
{
	print_r($day); echo '<hr>';
}

// but this - throw error "General error: 2050"
$result = $db->Query();
foreach ($result as $day)
{
	print_r($day); echo '<hr>';
}

// this also throw same error
$result = $db->Query();
foreach ($result as $day)
{
	print_r($day); echo '<hr>';
}

?>

Given result:

Array ( [created] => 1134531133 [0] => 1134531133 [day] => 732659 [1]
=> 732659 [count] => 3 [2] => 3 ) 
Array ( [created] => 1134711133 [0] => 1134711133 [day] => 732661 [1]
=> 732661 [count] => 1 [2] => 1 ) 
Array ( [created] => 1134811133 [0] => 1134811133 [day] => 732662 [1]
=> 732662 [count] => 1 [2] => 1 ) 
Array ( [created] => 1134911133 [0] => 1134911133 [day] => 732663 [1]
=> 732663 [count] => 1 [2] => 1 ) 

Warning: main() [function.main]: SQLSTATE[HY000]: General error: 2050
in /home/test/pages/pdobug.php on line 37

Warning: main() [function.main]: SQLSTATE[HY000]: General error: 2050
in /home/test/pages/pdobug.php on line 43

------------------------------------------------------------------------

[2005-12-24 14:31:05] tony2001@php.net

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.



------------------------------------------------------------------------

[2005-12-24 03:15:35] deadman_great at mail dot ru

Description:
------------
Current script works fine on localhost (winxp), and throw errors on
remote server (rh-fedora).

Software:
Local: winxp-sp2,php-5.1.1,mysql-5.0.3
Remote: fedora-c2,php-5.1.1,mysql-5.0.9

Reproduce code:
---------------
$query = 'SELECT created, to_days(from_unixtime(created)) as
day,count(id) as count FROM orders WHERE
partner=:partner AND
created>=:date GROUP BY day';

$vars = array(':partner'=>9,':date'=>1132797644);

$stm = $pdo->Prepare($query);
$result = $stm->Execute($vars);
foreach ($result as $day) // LINE-123
{
...
}

Expected result:
----------------
Rows.

Actual result:
--------------
Warning: main() [function.main]: SQLSTATE[HY000]: General error: 2050
in ... on line 123


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=35793&edit=1


Thread (43 messages)

« previous php.bugs (#90998) next »