Jump to content

cybernet

Members
  • Posts

    88
  • Joined

  • Last visited

About cybernet

  • Birthday 02/19/1991

Contact Methods

  • Website URL
    http://xLiST.ro/
  • Yahoo
    xlist_ro

Profile Information

  • Gender
    Male
  • Location
    /usr/sbin/mysqld
  • Age
    69

cybernet's Achievements

Member

Member (2/5)

0

Reputation

  1. please stop mocking me i presume it should be "private" instead of "static" ... right ?
  2. does anyone know a class that can generate a menu with category and subcategory that connects to mysql with pdo ? thank you
  3. so i found a pdo class to connect to mysql with pdo and looks easy to customize however i have an error that i can't figure it out class <?php class ApplicationResourcePool { static var $_dbHandle; // line 5 private static $_dbConfig = array( 'dsn' => 'mysql:dbname=vax', 'username' => 'vax', 'password' => 'veryrandpasswd', ); public static getDbHandle(){ if(self::$_dbHandle == null){ self::$_dbHandle = new PDO( self::$_dbConfig['dsn'] , self::$_dbConfig['username'], self::$_dbConfig['password'] ); } return self::$_dbHandle; } } class StockMapper { protected $_dbh; public __construct($dbh = null) { if($dbh == null){ $this->_dbh = ApplicationResourcePool::getDbHandle(); } else { $this->_dbh = $dbh; } } public getStockById($stockId){ $sth=$this->_dbh->prepare("SELECT * from stock WHERE id = :stockId"); $sth->bindParam(":stockId", $stockId); $sth->execute(); $result = $sth->fetch(PDO::FETCH_ASSOC); return $result[0]; } } $stockMapper = new StockMapper(); $stockData = $stockMapper->getStockById('302'); ?> Parse error: syntax error, unexpected 'var' (T_VAR), expecting variable (T_VARIABLE) in /path/index.php on line 5 i really don't know what to do
  4. i think i forgot to mention, simple ... but still i gave the example above
  5. never mind i helped my::self
  6. can anyone of you can give me a database class that uses PDO ? something like this class SQL { private static $dbh = null; private function __construct($host, $user, $pass, $data, $table) { $this->host = (!empty($host)) ? $host: 'localhost'; $this->user = $user; $this->pass = $pass; $this->data = $data; $this->table = $table; static::connect(); } private function __destruct() { static::close(); } public static function connect() { $dsn = 'mysql:dbname=' . $this->table . ';host=' . $this->host; static::$dbh = new PDO($dsn, $this->user, $this->pass); static::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } public static function close() { static::$dbh = null; } public static function query($query) { $sth = static::$dbh->prepare($query); $sth->execute(); } } but should include query count, if possible
  7. // bump no one ?
  8. i've tried and it's not working give me a little help please
  9. 1. Send the data as a parameter instead, like you've done with the $name. 2. yes, i was asking for a class that could use PDO like this one class SQL { private static $dbh = null; private function __construct($host, $user, $pass, $data, $table) { $this->host = (!empty($host)) ? $host: 'localhost'; $this->user = $user; $this->pass = $pass; $this->data = $data; $this->table = $table; static::connect(); } private function __destruct() { static::close(); } public static function connect() { $dsn = 'mysql:dbname=' . $this->table . ';host=' . $this->host; static::$dbh = new PDO($dsn, $this->user, $this->pass); static::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } public static function close() { static::$dbh = null; } public static function query($query) { $sth = static::$dbh->prepare($query); $sth->execute(); } } so now i should use : function userlogin($db) { unset($GLOBALS["CURUSER"]); } // etc instead of : function userlogin() { global $db; unset($GLOBALS["CURUSER"]); } // etc ?
  10. i said that pdo is a class, because at the time i wrote the post, i remembered a code line that began with class XyZ extends DB { ... where DB was the pdo connect thing ... @Christian F, thank you for the information you really clarified that error for me
  11. function get_cookie($name) { global $ResT_BV; if ( isset($_COOKIE[$ResT_BV['cookie_prefix'].$name]) AND !empty($_COOKIE[$ResT_BV['cookie_prefix'].$name]) ) { return urldecode($_COOKIE[$ResT_BV['cookie_prefix'].$name]); } else { return FALSE; } } function getip() { if (isset($_SERVER)) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && validip($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && validip($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } else { $ip = $_SERVER['REMOTE_ADDR']; } } else { if (getenv('HTTP_X_FORWARDED_FOR') && validip(getenv('HTTP_X_FORWARDED_FOR'))) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_CLIENT_IP') && validip(getenv('HTTP_CLIENT_IP'))) { $ip = getenv('HTTP_CLIENT_IP'); } else { $ip = getenv('REMOTE_ADDR'); } } return $ip; } i didn't include this in the 1st post because they were irrelevant to the issue i'm having so does anyone have a simple class { database } to use with pdo ? please
  12. well, as you can see in my signature i'm a MySQL freak so i would like to create a class that extends pdo and connects to mysqli i want to use pdo because it's safe for queries for now all i want is a class that connects to MySQL with mysqli ( it's supposed to be iMproved ), one that has a query count, and possible a way to cache queries for start if you could help only with the class, and the rest i will try to figure out myself thanks in advance
  13. if i would do that, then i have to call userlogin() on each page. on a search on google i found that i should create a class to connect to database, but i really don't know how to make it secure and flawless http://stackoverflow...object-php-help i found some tuts online, but there are many stuff that i don't need ( at least for know ) this would be an example http://www.tiny-thre...o-class-update/ i know that i sound very ... n00b and dumb also, but i really need an advice here @muddy i've checked youre blog and i saw that you have something there with classes http://muddy-dev.blogspot.ro/2012/10/php-classes-simple-sample-class.html but i didn't find a class that extends pdo ( mysql ) can you give me a tip, tutorial, something ?
  14. 1. none :-\ 2. like i said this is the first time i'm using pdo ... so i did how i thought at the moment how should i proceed ? can you please help me thanks in advance
×
×
  • 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.