Jump to content

criostage

Members
  • Posts

    42
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

criostage's Achievements

Member

Member (2/5)

0

Reputation

  1. Wow tyvm guys this have been very usefull, i always look foward to keep learning
  2. hi, i dont know what to say but wierdly enough ... it does help, the connection is nearly instant using 127.0.0.1. In terms of networking i know localhost is the same as 127.0.0.1, do you mind explaining why with localhost takes 'way longer'? The reason why i m asking is mainly for self study ... and tyvm for your reply, i will mark as solved if anyone can explain me ...
  3. Hello all, this is just one of those questions that i think that have an rather quick awnser. I m concerned about the PDO connection i made witch takes some time to stablish, i was using an self made class where dynamicly i create the dsn get the values etc etc .. when i stabilish the connection takes up to 1.5 seconds to finish (where without the line that makes the connection takes 0.01s for the script to finish), so i tested out with just these 4 lines of code and i get the same result as my class. $dsn = 'mysql:host=localhost;port=3306;dbname=MyDatabase;charset=UTF8'; $username = 'root'; $passwd = ''; $sqlhandler = new PDO($dsn, $username, $passwd); The code i m using to mesure the the finish time (i found this in the php website): function convert($size){ $unit=array('b','kb','mb','gb','tb','pb'); return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; } echo '<b>Memory used</b>: '. convert(memory_get_usage(true)).'<br>'; My "development" Enviroment is Windows 8.1 with EasyPHP 13.1 Dev Server (with PHP 5.5). My question is it's normal that just the connection takes this much to get completed? Thanks in advance
  4. As the title say's i need an critic opinion on the code i did, as i m learning all by my "self" sometimes i miss some feedback on what is best to do or not, so if anyone could throw a couple of tips or warnings please fell free to. This is the code i have: if( !defined('COREPATH') ) die('Accessing this file directly is not allowed'); defined( 'PS' ) or define( 'PS', PATH_SEPARATOR ); class autoloader{ private $_includePath = null; public function __construct() { $this->_includePath = get_include_path(); } public function register(){ spl_autoload_register( array( __CLASS__, 'loadClass' ) ); } public function unregister(){ spl_autoload_unregister( array( __CLASS__, 'loadClass' ) ); } public function addClassPath( $path ){ $this->_includePath .= PS . $path; } private function setIncludePaths(){ set_include_path( $this->_includePath ); } public function loadClass( $name ){ if( $this->_includePath != get_include_path() ){ $this->setIncludePaths(); } include $name.'.php'; } } $autoloader = new autoloader(); $autoloader->register(); $autoloader->addClassPath( CORECLASSES ); $madb = new database(); Thank you in advance.
  5. tyvm for the requinix that was very helpfull.
  6. I m using this magic method to create an function to avoid creating diferent set and get functions within this class for each variable example: class MyClass{ protected static $name; protected static $age; public static function __callStatic($name, $arguments) { $methodPrefix = substr($name, 0,3); $methodProperty = strtolower(substr($name, 3)); self::$name = 'Allan'; self::$age = '20'; #echo self::$name; switch( $methodPrefix ) { case 'get': return self::${$methodProperty}; break; } } } echo 'Hello my name is '. MyClass::getName() . ' and i m ' . MyClass::getAge() .' years old'; The output will be "Hello my name is Allan and i m 20 years old", and btw this code have already the code that i got from requinix reply, so it's working. Tyvm that did the trick , would you mind pointing me out the logic behind it?
  7. Hello, i m trying to learn magic method's and i have an small question on something that probably it's extremely easy, but i m not getting there ... Here's the "simple" code i got: class MyClass{ protected static $name; public static function __callStatic($name, $arguments) { $methodPrefix = substr($name, 0,3); $methodProperty = strtolower(substr($name, 3)); self::$name = 'Allan'; echo self::$name; switch( $methodPrefix ) { case 'get': return self::$methodProperty; break; } } My objective is to remove all the get and set's we you usually use in the code so i m using the __callStatic in order to retrieve or set variables inside the class, for example setName('John'). My question is if i want get the value of the protected static variable called name, usually you would just do return self::name, but let's say i have an more evolved class and i have several protected static variables (like age, genre), so here an small issue comes into my mind, how can i use the the content of the variable $methodProperty to return the proper protected static variable? My attempts resulted in the following error: Fatal error: Access to undeclared static property: MyClass::$methodProperty i understand the error but i have no idea how to work it arround... Thanks in advance.
  8. Hi thank you for your response, i did a couple of tests (including installing php 5.3.3) i get the same result as i described. I further found that mdbtools (the driver that was installed in the unixODBC) last version is from the year 2004, at this point i have no idea what to do ... thank you very much for your reply tho.
  9. Hello all, i m doing this small piece of code to test out how can i get some data out of an mdb file, so i can peridicly check it and import new data into something easier to work with ... example MySQL. This script is to runned as a cron job, so i m running it using the php cli, this is the code i have so far: <?php error_reporting(E_ALL); ini_set( 'display_errors', 1 ); $mdbfile = "/var/www/html/db.mdb"; if( file_exists( $mdbfile ) ){ try { $dbh = new PDO("odbc:DRIVER={MsAccess};DSN=mdbtest;"); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }catch (PDOException $e) { echo $e->getMessage(); } }else{ die('File does not exist!'); } foreach ( $dbh->query("SELECT * FROM MY_TABLE") as $row ){ echo $row['Row1']; } if(isset($dbh)){ $dbh = null; } ?> when i run "php -f /var/www/html/php-pdo-odbc.php", i get the error "Segmentation fault", if i try to open the file from the web browser i get an error "The connection was reset". Commenting out some code i figured out that the error is in the foreach, but i dont see any issue with it .. could anyone give me an though why is this happening? I m using CentOS 6.4 with Apache 2 and PHP5.5.6. Thanks in advance
  10. So i guess i was right on my first bunches, tyvm for the information and sorry for the newbish question i was only used to do small scripts this will help me in the future.
  11. The $AppOptions is set in the Main.php File: <?php /** * Array that contains the application settings to be applied at it's startup. */ $appOptions = array ( 'Developer' => TRUE, 'Timezone' => 'Europe/Lisbon', ); The idea would be to apply this array to the bootstrap, in the furure i would like to add more options to that file
  12. Hello, I would like to request a little of help in my code, I m trying to do an database for my movies in php, instead of using an framework or just do code without any structure, i decided to try adventure my self into higher grounds and try to make the application as a little framework that i could use for future projects the main reason behind this is mainly to learn proper PHP programing skills. In the past few weeks i have read online and changed my code so many times but or i m not understanding the class programing style or i m missing something. Here's my Work so far: Index.php <?php defined( 'DS' ) or define( 'DS', DIRECTORY_SEPARATOR ); defined( 'ABSPATH' ) or define( 'ABSPATH', dirname(__DIR__) ); defined( 'SYSPATH' ) or define( 'SYSPATH', ABSPATH . DS . 'System' ); defined( 'WEBPATH' ) or define( 'WEBPATH', ABSPATH . DS . 'Public' ); defined( 'PKGPATH' ) or define( 'PKGPATH', ABSPATH . DS . 'Packages' ); defined( 'APPPATH' ) or define( 'APPPATH', PKGPATH . DS . 'Application'); defined( 'COREPATH' ) or define( 'COREPATH', PKGPATH . DS . 'Framework' ); require ( PKGPATH . DS . 'Bootstrap.php'); Bootstrap.php <?php class Bootstrap{ static protected $_appConfig; static public function init ( ){ self::$_appConfig = APPPATH . DS . 'Config' . DS . 'Main.php'; require self::$_appConfig; var_dump($appOptions); } static private function setEnv( $appOptions ){ /** Set application enviroment to developer or 'production' */ Switch( is_bool( $appOptions['Developer'] ) ? $appOptions['Developer'] : FALSE ){ case TRUE: error_reporting( E_ALL ); ini_set( 'display_errors','On' ); break; default: error_reporting( E_ALL ); ini_set( 'display_errors', 'Off' ); ini_set( 'log_errors' ); ini_set( 'error_log', SYSPATH . DS . 'logs' . DS . 'errors.log' ); break; } /** Set's default timezone for this application */ date_default_timezone_set($appOptions['Timezone']); } } Bootstrap::init(); var_dump($appOptions); The Main.php file only contains the array appOptions (for now), i m thinking in the future adding the Database connection and Application requirements (example if you need mysql or gd modules installed). Okay now focusing on my question a little the output of the code above delivers the follow: array(2) { ["Developer"]=> bool(true) ["Timezone"]=> string(13) "Europe/Lisbon" } Notice: Undefined variable: appOptions in C:\EasyPHP\data\localweb\Framework\Packages\Bootstrap.php on line 33 NULL Note: 1st line is from the var_dump inside the init and 2nd is from outside the bootstrap class. With this i assume that the require i do in the init function only includes the file for the class and not for the application over all? is this the best way of doing an bootstrap or there's an better way? Thanks in advance,
  13. Got it i will read a little bit more on the internet about this, passing the object from class to class seen's a bit painful but like you said, if i use it this way there's no point in using classes. TYVM for the explanation =)
  14. yeah that worked, tyvm. just a question tho, if i use it this way (with the objects) i will have always to pass the object so it can be used inside the class, for example: <?php include (class.authentication.php); include (class.mysql.php); $authobj = new authentication(); $mysqlobj = new mysql(); $login = authobj->login( $username, $password, $mysqlobj) then inside the class.authentication.php <?php class authentication{ protected $loginquery = ''; public function login( $username, $password, $mysqlobj ){ $querylogin = $mysqlobj->checkauth( $username,$password ); } } This way things wont become a little more complicated to manage? or there's an easier way to accomplish this? thanks again in advance =)
  15. Hi thanks for the reply, i already had that in other file (called init.php), sorry for not mention it this is the content of the file: <?php # The PHP extention files are usually protected by the webserver, but abit of # extra protection never hurted anyone. if( !defined('abspath')){die("Accessing this file directly is not allowed." );} # This file will initialize all classes so they will be usable for the remaining # PHP script files. require_once( classes.'class.mysql.php'); require_once( classes.'class.authentication.php' ); # Start the classes as an object $mysqlobj = new mysql($dbhost, $dbport, $dbname, $dbuser, $dbpass); $authobj = new authentication(); ?> I didnt mention it because i have some files already and post them all is kinda ... but if needed let me know i will try to post it some where.
×
×
  • 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.