[PHP] Re: Newbie is trying to set up OOP With PHP and MySQL or MySQLi database class (using CRUD)
Thanks for all the help folks, PHP-light-PDO-Class ok well I found this... https://github.com/poplax/PHP-light-PDO-Class But it does not seem to recognize the port - I put the port as 8889 but keeps saying can't connect port 3306 Warning: PDO::__construct() [pdo.--construct]: [2002] Connection refused (trying to connect via tcp://127.0.0.1:3306) in /Users/revdave/Sites/php-fool/pdo3/PHP-light-PDO-Class-master/class.lpdo.php on line 33 Connection failed: SQLSTATE[HY000] [2002] Connection refused BTW: I tried to add the port a few places but it didn't work.. How do we fix this? -- config.php ?php $config = array(); $config['Database'] = array(); $config['Database']['dbtype'] = 'mysql'; $config['Database']['dbname'] = 'tester'; $config['Database']['host'] = '127.0.0.1'; $config['Database']['port'] = 8889; $config['Database']['username'] = 'root'; $config['Database']['password'] = 'root'; $config['Database']['charset'] = 'utf8'; ? === class.lpdo.php ?php /** * * @Author : Poplax [Email:linjiang9...@gmail.com]; * @Date : Fri Jun 03 10:17:17 2011; * @Filename class.lpdo.php; */ /** * class lpdo PDO * one table support only */ class lpdo extends PDO { public $sql = ''; public $tail = ''; private $charset = 'UTF8'; private $options; /** * * @Function : __construct; * @Param $ : $options Array DB config ; * @Return Void ; */ public function __construct($options) { $this-options = $options; $dsn = $this-createdsn($options); $attrs = empty($options['charset']) ? array(PDO::MYSQL_ATTR_INIT_COMMAND = SET NAMES . $this-charset) : array(PDO::MYSQL_ATTR_INIT_COMMAND = SET NAMES . $options['charset']); try { parent::__construct($dsn, $options['username'], $options['password'], $attrs); } catch (PDOException $e) { echo 'Connection failed: ' . $e-getMessage(); } } /** * * @Function : createdsn; * @Param $ : $options Array; * @Return String ; */ private function createdsn($options) { return $options['dbtype'] . ':host=' . $options['host'] . ';dbname=' . $options['dbname']; } /** * * @Function : get_fields; * @Param $ : $data Array; * @Return String ; */ private function get_fields($data) { $fields = array(); if (is_int(key($data))) { $fields = implode(',', $data); } else if (!empty($data)) { $fields = implode(',', array_keys($data)); } else { $fields = '*'; } return $fields; } /** * * @Function : get_condition; * @Param $ : $condition Array, $oper String, $logc String; * @Return String ; */ private function get_condition($condition, $oper = '=', $logc = 'AND') { $cdts = ''; if (empty($condition)) { return $cdts = ''; } else if (is_array($condition)) { $_cdta = array(); foreach($condition as $k = $v) { if (!is_array($v)) { if (strtolower($oper) == 'like') { $v = '\'%' . $v . '%\''; } else if (is_string($v)) { $v = '\'' . $v . '\''; } $_cdta[] = ' ' . $k . ' ' . $oper . ' ' . $v . ' ' ; } else if (is_array($v)) { $_cdta[] = $this-split_condition($k, $v); } } $cdts .= implode($logc, $_cdta); } return $cdts; } /** * * @Function : split_condition; * @Param $ : $field String, $cdt Array; * @Return String ; */ private function split_condition($field, $cdt) { $cdts = array(); $oper = empty($cdt[1]) ? '=' : $cdt[1];
[PHP] Re: Newbie is trying to set up OOP With PHP and MySQL or MySQLi database class (using CRUD)
dealTek wrote: Thanks for all the help folks, PHP-light-PDO-Class ok well I found this... https://github.com/poplax/PHP-light-PDO-Class But it does not seem to recognize the port - I put the port as 8889 but keeps saying can't connect port 3306 Warning: PDO::__construct() [pdo.--construct]: [2002] Connection refused (trying to connect via tcp://127.0.0.1:3306) in /Users/revdave/Sites/php-fool/pdo3/PHP-light-PDO-Class- master/class.lpdo.php on line 33 Connection failed: SQLSTATE[HY000] [2002] Connection refused BTW: I tried to add the port a few places but it didn't work.. How do we fix this? -- config.php ?php $config = array(); $config['Database'] = array(); $config['Database']['dbtype'] = 'mysql'; $config['Database']['dbname'] = 'tester'; $config['Database']['host'] = '127.0.0.1'; $config['Database']['port'] = 8889; $config['Database']['username'] = 'root'; $config['Database']['password'] = 'root'; $config['Database']['charset'] = 'utf8'; ? Change host to localhost - your mysql may be configured not to accept requests via tcp. === class.lpdo.php SNIP -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- Cheers David Robley My karma ran over my dogma -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Newbie is trying to set up OOP With PHP and MySQL or MySQLi database class (using CRUD)
On Feb 14, 2013, at 9:49 AM, dealTek deal...@gmail.com wrote: Hi everybody, Newbie is trying to set up OOP With PHP and MySQL or MySQLi database class (using CRUD) Simple story: creating this class database by myself is way over my head. So it be best for me to find something on the Internet that has already been created and working to pro specs (using CRUD with good security etc). In my studying, it seems that there is a difference between MySQL and MySQLi - MySQLi being the preferred choice if I understand correctly. There are lots of examples on the Internet however I don't know enough about it to know a good starting example from a bad starting example, so I would much appreciate any assistance pointing me towards a good starting point This seems a good start to me untrained eye, but it seems to be for mysql - not mysqli... http://net.tutsplus.com/tutorials/php/real-world-oop-with-php-and-mysql/ http://www.dreamincode.net/forums/topic/223360-connect-to-your-database-using-oop-php5-with-mysql-and-mysqli/ http://snipplr.com/view/8417/ http://snipplr.com/view/12535/ any assistance is appreciated! An Here Jeffry Way discusses the PDO API http://net.tutsplus.com/tutorials/php/php-database-access-are-you-doing-it-correctly/ -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Newbie is trying to set up OOP With PHP and MySQL or MySQLi database class (using CRUD)
Also worth checking http://justinvincent.com/ezsql Which is the class behind the WordPress' wpdb class. This is a great read too - http://www.devarticles.com/c/a/MySQL/PHP-and-Databases-for-the-Lazy-Sod/ On Thu, Feb 14, 2013 at 10:30 AM, dealTek deal...@gmail.com wrote: On Feb 14, 2013, at 9:49 AM, dealTek deal...@gmail.com wrote: Hi everybody, Newbie is trying to set up OOP With PHP and MySQL or MySQLi database class (using CRUD) Simple story: creating this class database by myself is way over my head. So it be best for me to find something on the Internet that has already been created and working to pro specs (using CRUD with good security etc). In my studying, it seems that there is a difference between MySQL and MySQLi - MySQLi being the preferred choice if I understand correctly. There are lots of examples on the Internet however I don't know enough about it to know a good starting example from a bad starting example, so I would much appreciate any assistance pointing me towards a good starting point This seems a good start to me untrained eye, but it seems to be for mysql - not mysqli... http://net.tutsplus.com/tutorials/php/real-world-oop-with-php-and-mysql/ http://www.dreamincode.net/forums/topic/223360-connect-to-your-database-using-oop-php5-with-mysql-and-mysqli/ http://snipplr.com/view/8417/ http://snipplr.com/view/12535/ any assistance is appreciated! An Here Jeffry Way discusses the PDO API http://net.tutsplus.com/tutorials/php/php-database-access-are-you-doing-it-correctly/ -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- Thanks, Dave - DealTek deal...@gmail.com [db-3] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php