Jump to content

chiprivers

Members
  • Posts

    468
  • Joined

  • Last visited

    Never

Everything posted by chiprivers

  1. Sorted I was using private instead of protected on my properties. I said I was new
  2. I am tackling my first major PHP application using OOP and I am getting a little stuck with extending classes. I want to be able to create a parent class which contains a number of properties and methods, and be able to extend this class with the ability to access the parent properties and methods. The specific problem I am having at the moment is with a property holding a MySQL connection. ie. class DatabaseManager { private $mysqli; public function DatabaseManager() { $this->mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE); } // various generic database methods declared here } class AnotherClass extends DatabaseManager { public function AnotherClass() { $this->DatabaseManager(); } public function methodUsingMysqli($query) { $result = $this->mysqli->prepare($query); // do something with result blah blah } } When I try an run my application using the above construct and trying to access the $mysqli property declared in the parent class, it says that it does not exist.
  3. How do I create alternative contractor methods for my class. Like when you create a DateTime object you can create it using an alternative time passed by a string using DateTime::createFromFormat(). I want to have a default constructor method but a couple of extra contractor methods that can be called when the instance is created.
  4. It does have permission - it works when using mysql_connect()
  5. I have just set up MAMP on my new MacBook Pro and I am having trouble getting my MySQL connection working. When I use the following code: $mysqli = new mysqli('localhost', 'application', 'application', 'dorset'); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (".$mysqli-errno.") ".$mysqli->connect_error; } I get this error: Failed to connect to MySQL: () Access denied for user 'application'@'localhost' (using password: YES) However if I use the old mysql_connect() function, it doesnt throw back any errors?! Any ideas?
  6. I am writing a function to update an existing record and I want to be able to return the values from the updated record prior to the update. ie. A record in table 'employee' has values id = 1, first_name = 'Joe' and last_name = 'Bloggs' The function is passed employee id 1 and new name Tom Cobley so the function will update record 1 with the respective name entries. Easy enough! However, I want the function to be able to return the old name, Joe Bloggs. Can this be done with a single query which updates the record with the specified values but also returns the old values at the same time or do I have to first query for the values of record 1 and then run a second update query?
  7. I'm not actually using PHP and MySQL for this query, I am using MS Access which is querying an Oracle database. I have posted here as I usually work with PHP and MySQL and as I understand it SQL is pretty much SQL which ever application I am using. I think the problem with the query is due to Access not liking the comparison between INT and VARCHAR so although it would probably normally work in SQL I need to try and work around the MS Access issue.
  8. I am struggling with a table join where the comparitive table fields are in different formats; one int and one var. I know that this is sloppy database construction but unfortunately it is not my database and I do not have any control over the table construction. In my query I have a join as below: SELECT ... ... FROM tableA LEFT JOIN tableB ON tableA.varField = tableB.intField Unfortunately this is not running because the datatypes in the fields that I am joining on are not the same datatype. Is there a function I can use to change the var value to an int before comparing it, or vice versa? I think from googling that I should be using cast() or convert() but I cannot find a clear explanation of these functions that has enabled me to workout if and how I could use either of these functions. Any help would be very much appreciated.
  9. thank you - that looks like it will work - will give it a go
  10. That looks good but do I also need to specify the year also to ensure that it only returns entries with a matching month in the current year and not say all records with a review date in October every year?
  11. Please could somebody help me with this, I assume, pretty simple SQL where clause... I have a DATE column in my table (field is called reviewdate) and I would like to return all records where the value in this column is within the current month. Could somebody help with the WHERE clause? Something like... WHERE functionformonthandyearof(reviewdate) = functionforcurrentmonthandyear() Many 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.