 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
douglazb Smarty Rookie
Joined: 16 Sep 2008 Posts: 5
|
Posted: Sat Oct 25, 2008 9:36 pm Post subject: Beginning PHP and MySQL E Commerce Book - Unexpected Error |
|
|
I am reading the book Beginning PHP and MySQL E-Commerce: From Novice to Professional by Cristian Darie & Emilian Balanescu. www.cristiandarie.ro/php-mysql-ecommerce
I'm stuck in Chapter 5 with the following error:
| Code: |
ERRNO: 256
TEXT: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
LOCATION: C:\tshirtshop\business\database_handler.php, line 100, at October 25, 2008, 5:01 pm
Showing backtrace:
trigger_error("SQLSTATE[HY000]: General error: 2014 Cannot execute queries whil...", "256") # line 100, file: C:\tshirtshop\business\database_handler.php
DatabaseHandler.GetAll("CALL catalog_get_departments_list()") # line 13, file: C:\tshirtshop\business\catalog.php
Catalog.GetDepartments() # line 34, file: C:\tshirtshop\presentation\departments_list.php
DepartmentsList.init() # line 16, file: C:\tshirtshop\presentation\smarty_plugins\function.load_presentation_object.php
smarty_function_load_presentation_object(Array[2], Object: Application) # line 5, file: C:\tshirtshop\presentation\templates_c\%%A5^A5A^A5A1C73D%%departments_list.tpl.php
include("C:\tshirtshop\presentation\templates_c\%%A5^A5A^A5A1C73D%%depart...") # line 1868, file: C:\tshirtshop\libs\smarty\Smarty.class.php
Smarty._smarty_include(Array[2]) # line 44, file: C:\tshirtshop\presentation\templates_c\%%41^412^412F4E3D%%store_front.tpl.php
include("C:\tshirtshop\presentation\templates_c\%%41^412^412F4E3D%%store_...") # line 1255, file: C:\tshirtshop\libs\smarty\Smarty.class.php
Smarty.fetch("store_front.tpl", null, null, true) # line 1105, file: C:\tshirtshop\libs\smarty\Smarty.class.php
Smarty.display("store_front.tpl") # line 26, file: C:\tshirtshop\index.php
|
The file C:\tshirtshop\business\database_handler.php
| Code: |
<?php
// Class providing generic data access functionality
class DatabaseHandler
{
// Hold an instance of the PDO class
private static $_mHandler;
// Private constructor to prevent direct creation of object
private function __construct()
{
}
// Return an initialized database handler
private static function GetHandler()
{
// Create a database connection only if one doesn’t already exist
if (!isset(self::$_mHandler))
{
// Execute code catching potential exceptions
try
{
// Create a new PDO class instance
self::$_mHandler =
new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD,
array(PDO::ATTR_PERSISTENT => DB_PERSISTENCY));
// Configure PDO to throw exceptions
self::$_mHandler->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
// Return the database handler
return self::$_mHandler;
}
// Clear the PDO class instance
public static function Close()
{
self::$_mHandler = null;
}
// Wrapper method for PDOStatement::execute()
public static function Execute($sqlQuery, $params = null)
{
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute query
$statement_handler->execute($params);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
// Wrapper method for PDOStatement::fetchAll()
public static function GetAll($sqlQuery, $params = null,
$fetchStyle = PDO::FETCH_ASSOC)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetchAll($fetchStyle);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
// Wrapper method for PDOStatement::fetch()
public static function GetRow($sqlQuery, $params = null,
$fetchStyle = PDO::FETCH_ASSOC)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetch($fetchStyle);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
// Return the first column value from a row
public static function GetOne($sqlQuery, $params = null)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetch(PDO::FETCH_NUM);
/* Save the first value of the result set (first column of the first row)
to $result */
$result = $result[0];
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
}
?>
|
Has anyone else experienced this error? Or have a work-around / solution?
I am using Windows XP (Service Pack 3), Apache (2.2.9 ) and PHP (5.2.6) installed from XAMPP for Windows (from apachefriends org).
Thank you in advance,
Douglazb |
|
| Back to top |
|
phantom47 Smarty n00b
Joined: 26 Oct 2008 Posts: 1
|
Posted: Sun Oct 26, 2008 6:06 pm Post subject: General error: 2014 Cannot execute queries while ...... |
|
|
Checkout Cristian Darie's website entry for this book to get the fix. I would have posted the answer but apparently I must have 3 posts before I can post links  |
|
| Back to top |
|
douglazb Smarty Rookie
Joined: 16 Sep 2008 Posts: 5
|
Posted: Sun Oct 26, 2008 6:42 pm Post subject: |
|
|
Bingo! That fixed it.
I did not think to look on his website.
Issue resolved!
Thank you!
Douglas |
|
| Back to top |
|
dqsmith Smarty n00b
Joined: 04 Feb 2009 Posts: 1
|
Posted: Wed Feb 04, 2009 3:20 pm Post subject: the link on christiandarie.ro website is not working |
|
|
Hi,
When I click that link about the php_pdo_mysql.dll on christandarie.ro, it does not work, "The website declined to show this webpage".
Does anyone know what is the correct link for this php_pdo_mysql.dll? because I get also the same error.
Thanks. |
|
| Back to top |
|
lastcowboy Smarty n00b
Joined: 12 Feb 2009 Posts: 3
|
Posted: Thu Feb 12, 2009 1:08 pm Post subject: |
|
|
i used the save link as to get the dll.
however when i put the dll in. i get the following error in my apache log.
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_pdo_mysql.dll' - %1 is not a valid Win32 application.\r\n in Unknown on line 0
on the screen i get a
ERRNO: 256
TEXT: could not find driver
LOCATION: D:\workspace\tshirtshop\business\database_handler.php, line 35, at February 12, 2009, 12:59 pm
Showing backtrace:
Please advise. |
|
| Back to top |
|
IanE11 Smarty n00b
Joined: 27 Feb 2009 Posts: 2
|
Posted: Fri Feb 27, 2009 3:23 pm Post subject: |
|
|
| lastcowboy wrote: | i used the save link as to get the dll.
however when i put the dll in. i get the following error in my apache log.
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_pdo_mysql.dll' - %1 is not a valid Win32 application.\r\n in Unknown on line 0
on the screen i get a
ERRNO: 256
TEXT: could not find driver
LOCATION: D:\workspace\tshirtshop\business\database_handler.php, line 35, at February 12, 2009, 12:59 pm
Showing backtrace:
Please advise. |
I get the same problem - any ideas? |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7062 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 27, 2009 3:25 pm Post subject: |
|
|
| You need the pdo dynamic library installed in PHP. |
|
| Back to top |
|
IanE11 Smarty n00b
Joined: 27 Feb 2009 Posts: 2
|
Posted: Fri Feb 27, 2009 4:04 pm Post subject: |
|
|
| it is installed |
|
| Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7062 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 27, 2009 4:16 pm Post subject: |
|
|
well I don't use PHP on windows, but this:
| Code: | PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_pdo_mysql.dll' - %1 is not a valid Win32 application.\r\n in Unknown on line 0
|
tells me PHP is unable to load it. |
|
| Back to top |
|
nedo Smarty Rookie
Joined: 30 Mar 2012 Posts: 8
|
Posted: Sat Mar 31, 2012 7:08 pm Post subject: |
|
|
hello evry1 m getting the same problem ..and i don't knw wt to do ..
Fatal error: could not find driver in F:\wamp\www\hatshop\business\database_handler.php on line 35
configfile.php
| Code: | define('DB_PERSISTENCY', 'true');
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'hatshopadmin');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'hatshop');
define('PDO_DSN', 'pgsql:host=' . DB_SERVER . ';dbname=' . DB_DATABASE);
|
databasehandler.php
| Code: |
<?php
// Class providing generic data access functionality
class DatabaseHandler
{
// Hold an instance of the PDO class
private static $_mHandler;
// Private constructor to prevent direct creation of object
private function __construct()
{
}
// Return an initialized database handler
private static function GetHandler()
{
// Create a database connection only if one doesn’t already exist
if (!isset(self::$_mHandler))
{
// Execute code catching potential exceptions
try
{
// Create a new PDO class instance
self::$_mHandler =
new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD,
array(PDO::ATTR_PERSISTENT => DB_PERSISTENCY));
// Configure PDO to throw exceptions
self::$_mHandler->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
// Return the database handler
return self::$_mHandler;
}
// Clear the PDO class instance
public static function Close()
{
self::$_mHandler = null;
}
// Wrapper method for PDOStatement::execute()
public static function Execute($sqlQuery, $params = null)
{
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute query
$statement_handler->execute($params);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
// Wrapper method for PDOStatement::fetchAll()
public static function GetAll($sqlQuery, $params = null,
$fetchStyle = PDO::FETCH_ASSOC)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetchAll($fetchStyle);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
// Wrapper method for PDOStatement::fetch()
public static function GetRow($sqlQuery, $params = null,
$fetchStyle = PDO::FETCH_ASSOC)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetch($fetchStyle);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
// Return the first column value from a row
public static function GetOne($sqlQuery, $params = null)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetch(PDO::FETCH_NUM);
/* Save the first value of the result set (first column of the first row)
to $result */
$result = $result[0];
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
}
?>
|
i don't knw wt should i do ..? if any 1 know then plz tell me |
|
| Back to top |
|
mohamed_bn Smarty n00b
Joined: 18 May 2012 Posts: 2
|
Posted: Fri May 18, 2012 8:45 am Post subject: PDO error on Windows: ERRNO: 256 TEXT: SQLSTATE[HY000]: Gene |
|
|
Simply you can download the right version of 'php_pdo_mysql.dll' then put it in the 'ext' folder of PHP by defaulf it is like this (C:\xampp\php\ext) ,
I tested this solution and it works well!
I already found the file on the book author website which is no longer available from the errata page of the book.
You can download it using this link: http://sharecash.org/download.php?file=2851057.
if the link is no longer available you can use this one: http://downloads.ziddu.com/downloadfile/19416149/php_pdo_mysql.dll.zip.html
| nedo wrote: | hello evry1 m getting the same problem ..and i don't knw wt to do ..
Fatal error: could not find driver in F:\wamp\www\hatshop\business\database_handler.php on line 35
configfile.php
| Code: | define('DB_PERSISTENCY', 'true');
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'hatshopadmin');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'hatshop');
define('PDO_DSN', 'pgsql:host=' . DB_SERVER . ';dbname=' . DB_DATABASE);
|
databasehandler.php
| Code: |
<?php
// Class providing generic data access functionality
class DatabaseHandler
{
// Hold an instance of the PDO class
private static $_mHandler;
// Private constructor to prevent direct creation of object
private function __construct()
{
}
// Return an initialized database handler
private static function GetHandler()
{
// Create a database connection only if one doesn’t already exist
if (!isset(self::$_mHandler))
{
// Execute code catching potential exceptions
try
{
// Create a new PDO class instance
self::$_mHandler =
new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD,
array(PDO::ATTR_PERSISTENT => DB_PERSISTENCY));
// Configure PDO to throw exceptions
self::$_mHandler->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
// Return the database handler
return self::$_mHandler;
}
// Clear the PDO class instance
public static function Close()
{
self::$_mHandler = null;
}
// Wrapper method for PDOStatement::execute()
public static function Execute($sqlQuery, $params = null)
{
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute query
$statement_handler->execute($params);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
// Wrapper method for PDOStatement::fetchAll()
public static function GetAll($sqlQuery, $params = null,
$fetchStyle = PDO::FETCH_ASSOC)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetchAll($fetchStyle);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
// Wrapper method for PDOStatement::fetch()
public static function GetRow($sqlQuery, $params = null,
$fetchStyle = PDO::FETCH_ASSOC)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetch($fetchStyle);
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
// Return the first column value from a row
public static function GetOne($sqlQuery, $params = null)
{
// Initialize the return value to null
$result = null;
// Try to execute an SQL query or a stored procedure
try
{
// Get the database handler
$database_handler = self::GetHandler();
// Prepare the query for execution
$statement_handler = $database_handler->prepare($sqlQuery);
// Execute the query
$statement_handler->execute($params);
// Fetch result
$result = $statement_handler->fetch(PDO::FETCH_NUM);
/* Save the first value of the result set (first column of the first row)
to $result */
$result = $result[0];
}
// Trigger an error if an exception was thrown when executing the SQL query
catch(PDOException $e)
{
// Close the database handler and trigger an error
self::Close();
trigger_error($e->getMessage(), E_USER_ERROR);
}
// Return the query results
return $result;
}
}
?>
|
i don't knw wt should i do ..? if any 1 know then plz tell me |
|
|
| Back to top |
|
robbin Smarty n00b
Joined: 06 Jul 2012 Posts: 1
|
Posted: Fri Jul 06, 2012 8:34 am Post subject: |
|
|
Thanks for taking time for sharing this post...i found a lot of informative stuff in your post keep it up thank you.
Online Ged Programs |
|
| Back to top |
|
bonduu01 Smarty n00b
Joined: 26 Jul 2012 Posts: 4
|
Posted: Thu Jul 26, 2012 2:32 pm Post subject: Beginning PHP and MySQL E-Commerce -help on chp 4 |
|
|
Help wanted: I have been reading Beginning PHP and MySQL E-Commerce to build my website, I am not a good php programmer and i have a problem with smarty 2.8.0.1, I have been battling to resolve in chapter 4.
This is the error i receive below:
ERRNO: 2
TEXT: unlink(C:\tshirtshop/presentation/templates_c\%%41^412^412F4E3D%%store_front.tpl.php): No such file or directory
LOCATION: C:\tshirtshop\libs\smarty\internals\core.write_file.php, line 44, at July 26, 2012, 2:09 pm
Showing backtrace:
unlink("C:\tshirtshop/presentation/templates_c\%%41^412^412F4E3D%%store_...") # line 44, file: C:\tshirtshop\libs\smarty\internals\core.write_file.php
smarty_core_write_file(Array[3], Object: Application) # line 29, file: C:\tshirtshop\libs\smarty\internals\core.write_compiled_resource.php
smarty_core_write_compiled_resource(Array[2], Object: Application) # line 1431, file: C:\tshirtshop\libs\smarty\Smarty.class.php
Smarty._compile_resource("store_front.tpl", "C:\tshirtshop/presentation/templates_c\%%41^412^412F4E3D%%store_...") # line 1254, file: C:\tshirtshop\libs\smarty\Smarty.class.php
Smarty.fetch("store_front.tpl", null, null, true) # line 1106, file: C:\tshirtshop\libs\smarty\Smarty.class.php
Smarty.display("store_front.tpl") # line 23, file: C:\tshirtshop\index.php
The version of smarty am using is 2.6.0 and xampp. |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|