Jump to content

Search the Community

Showing results for tags 'oop'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

  1. Hi guys! I am new here. I am having problems with my site that I am developing. Could you help me how to fix it. This is the complete error statement, Fatal error: Call to undefined method dbConnection::query() inC:\xampp\htdocs\koa\classes\class.ManageUsers.php on line 20. I am using PHP, and MySQL in an Object Oriented way. Here is the code in the class.ManageUsers.php that the error is pointing to. I will put the whole function here: function LoginUsers($username,$password){ $query = $this->db->query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"); $num_rows = $this->link->fetchRows(); return $num_rows; } The line 20 is: $query = $this->db->query("SELECT * FROM users WHERE username = '$username' AND password = '$password'"); Also the construct function here: function __construct(){ $this->db = new dbConnection(); $this->db->connect(); } The dbConnection class is this: class dbConnection{ protected $db_conn, $_query, $_numRows, $_fetchAll; public $db_name = '******'; public $db_user = '******'; public $db_pass = '******'; public $db_host = '******'; function connect(){ $this->db_conn = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name, $this->db_conn); if(mysql_errno($this->db_conn){ return mysql_error($this->db_conn); } else{ return $this->db_conn; } } public function query($sql){ $this->_query = mysql_query($sql, $this->db_conn); $this->_numRows = mysql_num_rows($this->_query); $this->_fetchAll = mysql_fetch_array($this->_query); } } ?> Thanks!
  2. Hi all, I'm looking to design a OO system that interacts with 3rd parties who use SOAP, GET AND POST. These 3rd parties each have their own way of more or less doing the same thing. For example. Say I want to pass them a credit card name, one 3rd party may expect "Mastercard" and another might expect "MSC" to be passed. At the moment I'm thinking I could, for example have a set method like so: $card->setMastercard("MASTERCARD"); Another method to find the correct mapping for it: $card->findMapped(); This may mean a scaleabilty problem if a new card is added in the future. I could create a method is some subclass that takes these details as params, perhaps something like: $thirdParty->('$URL_TO_POST_TO', 'SOAP' ,array(' "MSC" => "MASTERCARD, "VIS" => "VISA" '), // etc ); This would make it potentially a nightmare if a lot of params need passed in but would mean if another card was added, the code wouldn't need changed and it would just mean adding another element in the array. Anyone got any tips or suggestions on how best to tackle this? I'm thinking GET/POST/SOAP parent classes and a "3rd party" subclass. These are just rough ideas. Thanks in advance, CaptainChainsaw
  3. Hi, I tried to prefrom a mysql_fetch_array using OOP and i get the folloing error message. Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in .... filename I have created a class named mysql database, and inside that class I have included a method named "fetch_array". Below is how the code looks. (There are obviously other mehtods in that class i have just included the one I am having trouble with) <?php // I have created a file named database.php and created the class mySQLDatabase for that file class mySQLDatabase { public function fetch_array($result_set) { return mysql_fetch_array($result_set); } public function query($sql) { $result = mysql_query($sql, $this->connection); $this->confirm_query($result); // end of if (!$result) return $result; } // end of function query($sql) } $database = new mySQLDatabase();//Created an instance of the class to include in my user.php file. (Below) ?> then i have created a new file named user.php.. included the database.php and have created a class the preforms the queries called the "User" Class <?php class User { public static function find_all() { $result_set = self::find_by_sql("SELECT * FROM users"); return $result_set; } public static function find_by_id($id=0) { // I have pulled in the global $database variable that I have instantiated from the database.php file global $database; $result_set = self::find_by_sql("SELECT * FROM users WHERE id={$id} LIMIT 1"); // I used the find_by_sql(below) method to perform my functions for functions inside this class $found = $database->fetch_array($result_set); return $found; } public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); $return = $result_set; } } ?> Lastly on my index.php i used the static method to run the query and preform the mysql_fetch_array on the username and it doesn't seem to be working. here is how did this on the index.php file. $record = User::find_by_id(1); echo $record['username'];
  4. Hello Folks, I have a particular problem that I can't for the life of me sort out. The following function submits the query to the database and returns a result. function queryDB($field, $table, $where = "", $group = "", $sort = "", $limit = "") { $sql = "SELECT `$field` FROM `$table`" . $where . $group . $sort . $limit; $myresult = $this->db->myQuery($sql); $ech = ($myresult)?"Result is Good!": "Result is Bad: " .$myresult; echo $ech; $word = $this->db->fetchSingleValue($myresult, $field); return $word; } And it appears to work just fine for most of the queries I"m making, but for some reason, at one point it doesn't, and gives a bad result, with no discernable error. The info that is passed to the function is the Table, Field and the Where clause. What could possibly be causing the result to be bad? And yes, I've output the sql, and run it in phpMyAdmin, with success, so I'm really at a loss. Any help would be greatly appreciated. Ray
  5. Sorry if this is not the correct sub-forum, I just went through most sections and didn't really know the best place. I want to learn object oriented php but can't seem to find any resources which are written in good english. I was wondering if someone knows of any reliable resources for learning pdo? I've already looked on php.net but I wanted more of a tutorial based website written for novices. I hope someone can throw me a few links. Kind regards, L2c
  6. I have learned that static variables are shared through the inheritance tree. I got the following code from a tutorial I have been watching, and was wondering why when $foo is set to 3 it echos out "3" for class One, Two, and Three? class One { static $foo; } class Two extends One {}; class Three extends One {} One::$foo=1; Two::$foo=2; Three::$foo=3; echo One::$foo; echo Two::$foo; echo Three::$foo;
  7. Hello, I starting learning OOP, and I love it! I was playing around with access modifiers and came across something I had difficulty understanding. On The code below i set the function protected1() to be protected. Which is supposed to be accessed from the class or subclass so I created a subclass called example2 that extends example. Then i set $example1 to instantiated sub class example2 and called protected1() function, and it did not call work? Why is that? class Example { public function public1() { // Everywhere echo "This is Public"; } private function private1() { // This class only echo "This is private"; } protected function protected1() { // this and the subclasses only echo "This is protected"; } } class example2 extends example { } $example1 = new example2(); echo $example1->protected1();
  8. So I'm writing an api that my clients can use in their sites. I don't want to give them direct access to the code. I have the script on api.XXXXXX.com index.php contains: <?php require_once('base.php'); require_once('client.php'); class api extends client { function __construct($config = null) { return parent::__construct($config); } } //....Other Code ?> Is it possible for my clients to access the API class by including it in their site? For example: <?php require_once('http://api.XXXXXX.com/index.php'); class service{ private $client; function __construct() { $this->client = new api(); } } //....Other Code ?>
  9. Hey Guys, For the past view nights I have been watching videos and such about learning object oriented PHP. I don't understand when to use it. Can someone give me a simple example of when to use it?
  10. I am trying to change from using mysql to PDO, I heard it is very secure, but I think in-order to implement PDO, one needs to learn Object Oriented Programming for PHP. Is this true? And, if so Where can I find, the simplest and easiest to understand tutorials on the web for pdo, or oop.
  11. Hello, I've followed the whole series of Log in and registration system on the phpacademy channel on Youtube: http://www.youtube.com/playlist?list=PLE134D877783367C7 After reading some comments and doing some research I found that it uses md5 and old mysql_ function, which for some reason are 'deprecated' or not secure. I'm still not sure. Also, after doing some searching I came across: http://www.sunnytuts.com/article/login-and-registration-with-object-oriented-php-and-pdo which is another tutorial that is quite similar to the one on phpacademy, but it uses PDO and Object oriented programming and bcrypt instead of md5(). The problem is that I don't know OOP and I use procedural programming. So is it worth learning OOP and using bcrypt() instead of md5() or PDO instead of mysql? I mean, am I ok with using the code from phpacademy, or do I need to follow the other one and also learn OOP. Thank you very much.
  • 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.