Jump to content

DocSeuss

Members
  • Posts

    73
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling
  • Location
    Texas, USA

DocSeuss's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. You can use mysql in an OO way, based on your error message it's sounds like to me it problem is in the code that uses this class rather than the class itself. Maybe something like $mydbobject = new mysql(); which should be fine(I don't think that mysql by it's self is reserved), but it would be a problem since the class is actually named "db".
  2. I simply used a bit of code to demonstrate the use of the split function. I just assigned the variable to a static string value, you of course would have to derive the value as needed for your specific application. As you move forward in the learning process it will be rare to get someone to show you exactly the answer to your specific problem. More often than not they will point you to or give you the tools/info neccessary to accomplish the task.
  3. come on now, I'm not gonna make any bad comments here but your are trying to be at least a hobby programmer right? Both solutions above will work with any input string they simple break the string into parts via the split or the explode function. Though I have to admit the documentation does say that explode is a better choice than split if you do not need to use regular expressions.
  4. mysql_fetch_array returns a numbered array not an associative one. use mysql_fetch_assoc() or mysql_fetch_array($result, MYSQL_ASSOC);
  5. 1) I don't belive it has one yet. 2) you can try getAttribute documented here http://us.php.net/manual/en/pdo.getattribute.php
  6. 1) I would create the database object once in my main code and pass a reference to it to any other classes they may need to use a db connection. 2) I would move the actual connecting of the database out of the contruct and put into a child function. 3) this would be a non issue. Code may look something like this. $mydbobject = new database($server,$user,$pass,$database,$prefix = ''); // create a database object. $mydbobject->connect(); // connection member funtion inside database class only called once. $myuserobject = new user(); // create a user object. $login = $user->login($name, $pass, $mydbojbect); // call member function login of user class and do login logic. In this example it would return some message. There are many ways to go about it just try to think of a class as an object. There is nothing wrong with an object using another object. I'm sure you have read about the popular bicycle example when reading about OOP. Imagine if you also had a surface object, it could be a road, dirt trail, grass field, ect.. You wouldn't have the bicycle extend the surface object in order to move on it.
  7. There are several ways to accomplish what you are looking for, so I'm not sure what will be best for you. My first impulse is to just use the split method. $filename = "dragon.about.news"; $namearray = split(".", $filename); echo $namearray[0]."<br />"; echo $namearray[1]; output would be: dragon about
  8. My bad, meant to address my previous post to gazzafm, the original poster, not chronister, the gentlemen providing the assistance.
  9. LOL chronister, Understand the frustration, everyone on this board has been there. It's alot like the new guy coming into your restaurant and looks at you will a blank stare when you use words and phrases like Back of House, happy campers, cowboy chef, shoemaker, and my favorite the Chinese Microwave. He has no clue what your talking about. Anyway when you use the 'at symbol' @ in php it will suppress(prevent reporting) any errors the expression following it may throw. It is a very rare circumstance that you would do this, especially when your developing code. Hard to fix errors if you suppressed them and don't know what they are. I would go so far as to say someone learning PHP should never use it.
  10. Might be able to offer help if you be more specific about the problem you are having. Error...incorrect address.....ect. Is the database mysql?
  11. Well sure that would work, but if the purpose of the method is to be called from an instance of the object why wouldn't you just want to make it public anyway? The whole purpose of making a function or variable protected or private is because you don't want them to be directly accessed. If the logic of your class is that you(or anyone using your class) should be able to call $obj->work() to print out the line then by design the method should be public. Just sounds like your creating a second public class to call a protected one for no reason. It's not necessary to protect a method just because you can. 
  12. My host is still running php 4 so I can't personally test but I'm pretty sure if you change it protected or public it would work.
  13. This is much the same answer as to your other question variables declared as private are not available to any other class....they are not inherited.
  14. By declaring your method definition as protected it is not usable outside the class(or it's children). If you want to implement the method in code that would need access then it needs to be declared public. Amendem: The abstract protected is fine in the Manager class.
  15. ini_set('$variable to change, $value to change to) is a native php function that allows you to change ini variables during the run of the script. The values revert back to the original value after the script with the ini_set() function finishes.
×
×
  • 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.