next Posted July 15, 2008 Share Posted July 15, 2008 I wrapped PDO in my class but have a weird problem with my execute method: <?php class Database { private static $dbh; private function __construct() {} private static function connect() { if(!isset(self::$dbh)) { try { self::$dbh = new PDO(DB_DSN, DB_USER, DB_PASSWORD, array(ATTR_PERSISTENT => true)); } catch(PDOException $e) { self::close(); trigger_error($e->getMessage(), E_USER_ERROR); } } return self::$dbh; } public static function close() { self::$dbh = null; } public static function execute($sql) { try { $handle = self::connect(); $stmt = $handle->prepare($sql); $stmt->execute(); } catch(PDOException $e) { self::close(); trigger_error($e->getMessage(), E_USER_ERROR); } } public static function getAll($sql, $style = PDO::FETCH_ASSOC) { $result = null; try { $handle = self::connect(); $stmt = $handle->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll($style); } catch(PDOException $e) { self::close(); trigger_error($e->getMessage(), E_USER_ERROR); } return $result; } public static function getRow($sql, $style = PDO::FETCH_ASSOC) { $result = null; try { $handler = self::connect(); $stmt = $handler->prepare($sql); $stmt->execute(); $result = $stmt->fetch($style); } catch(PDOException $e) { self::close(); trigger_error($e->getMessage(), E_USER_ERROR); } return $result; } } ?> If you will look at getAll or getRow you'll notice that i have to type in the same lines of code: $handler = self::connect(); $stmt = $handler->prepare($sql); $stmt->execute(); these lines make up "execute" method: public static function execute($sql) { try { $handle = self::connect(); $stmt = $handle->prepare($sql); $stmt->execute(); } catch(PDOException $e) { self::close(); trigger_error($e->getMessage(), E_USER_ERROR); } } So if i try to replace getAll with this: public static function getAll($sql, $style = PDO::FETCH_ASSOC) { $result = null; try { $self::execute($sql); $result = $stmt->fetchAll($style); } catch(PDOException $e) { self::close(); trigger_error($e->getMessage(), E_USER_ERROR); } return $result; } i get an error: Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in E:\PortableApps\WOS\www\ahk_php\lib\Database.class.php on line 41 Why is this happening? Those are the same lines of code. Any idea? Link to comment https://forums.phpfreaks.com/topic/114779-really-weird-problem-with-wrapped-pdo/ Share on other sites More sharing options...
corbin Posted July 15, 2008 Share Posted July 15, 2008 Is "$self::execute($sql);" line 41 by any chance? Try self::execute($sql); Link to comment https://forums.phpfreaks.com/topic/114779-really-weird-problem-with-wrapped-pdo/#findComment-590210 Share on other sites More sharing options...
next Posted July 15, 2008 Author Share Posted July 15, 2008 lol, i always do that, thanks i'll try it out Link to comment https://forums.phpfreaks.com/topic/114779-really-weird-problem-with-wrapped-pdo/#findComment-590504 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.