Jump to content

Cine

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Everything posted by Cine

  1. I currently have this: Date("Y-m-d", $this->dob); ...which outputs 1970-01-01 and is stored in the database. I need a way of formatting that custom date string ($this->dob) into a format that MySQL can understand which is(Y-m-d). But I don't know how
  2. Hi there, I have a string '12/04/1990', that's in the format dd/mm/yyyy. I'm attempting to convert that string to a Date, and then insert that date into a MySQL DATE field. The problem is, every time I try to do so, I keep getting values like this in the database: 1970-01-01. Any ideas? Much appreciated.
  3. Ah I didn't think about the mysql_fetch_object() method. It would suit what I'm trying to achieve perfectly. Thanks.
  4. My thinking entirely. Thanks.
  5. Hi, appreciate your reply. The reason why I suggested using #1, was that there'll be quite a few 'get...' methods and other database interoperability methods in the 'ItemAbstraction' class and the advantage of them all calling one method in the 'Item' class, is that they can share a single persistent database connection, instead of establishing a new one for each query; which is what #2 would require. Thanks.
  6. Hi, I need some advice on how I should go about fetching data from a database, taking advantage of OOP principles. I have a table named 'items' in a Database. I've created a an 'Item' class, that holds all my instance variables for a specific item. These instance variables, can be directly associated with the fields I have in the table. I also have an 'ItemAbstraction' class, which is responsible for 'getting' items given an Item ID or name for example. My question is, which of the two methods below would work best? 1) Have a method in the 'ItemAbstraction' class that calls a 'getItems' method in the 'Item' class which queries the database and returns an associative array of items. Then, as I'm iterating through this array... create a 'Item' object for each returned item row, and set the instance variables in that object accordingly. I'll then store this object in my own subject array, which can be returned. 2) To simply have a method that returns the associative array of items returned by a successful database query? 3) Any other ways? Many thanks for the replies in advance.
  7. PFMaBiSmAd, thanks. Simply assigning the result from the query to some member variables works fine.
  8. Im thinking it HAS to be something to do with how I'm using save_results() and use_result(). But after scouring through the PHP docs, I've yet to come across anything that alludes to this. EDIT: Yeah, the store_result() function is returning false, which means an error occurred. Which explains why use_result() is returning an error. Now to find why it's failing?
  9. You said you didn't want to use a Database for this... is there any particular reason why? A Database would be much easier though, SQL queries make it simple to search through data sets will would be ideal for what you're looking to do. If you're set on not using a Database to hold the information on each Monster... you could use an XML file instead. Then use SimpleXML or another parser to extract the monster information.
  10. Hi there, I have a Database Abstraction class for MySQL. I'm trying to use the MySQLi::store_result() to save a result set returned by a successful SELECT query (MySQLi::query()). As soon as that is done (Or at any time), I call the member function getData() which I hoped would return an associative array of the stored SELECT data. However, I'm not sure if I'm doing this correctly at all. The code at present, is returning a Fatal error: The $data variable is being passed the result of calling use_result(), which is supposed to be an unbuffered result object. Currently however, it's returning False as something erroneous occurred. But I have no idea what. I've posted an extract of the class below. Thanks in advance. public function select($table, $fields, $condition = false) { if($this->isConnected()) { if(isset($table, $fields)) { $SQL = "SELECT "; foreach($fields as $column) { $SQL .= "`$column`"; $SQL .= ($column != end($fields)) ? ", " : " "; } $SQL .= "FROM $table "; $SQL .= ($condition) ? "WHERE $condition" : ""; $result = $this->query($SQL); if($result->num_rows > 0) { $this->DB->store_result(); return $this->getData(); } return 0; } else { echo self::ERR_SELECT_SYNTAX; return false; } } } public function getData() { $data = $this->DB->use_result(); return $data->fetch_assoc(); }
  11. Hello, Here's my system. Once a user is successfully logged in, a new instance of a User class is created. The constructor of this class grabs the details of the logged-in user from a database and stores them inside properties in the User class. The problem is, obviously I'd want to access these properties from any page I require them to be able to display user data, so I looked into storing the User object in a Session. When I tried implementing this, I ran into a bunch of errors and I couldn't figure it out. Here's an example: After a user has logged in, I had the following code: $_SESSION['user'] = new User($this->username); I was under the impression that this assigns a user object to a session. But it's not working as I receive this error: Then on the page I want to display the name of the current user logged-in, I had this code: $_SESSION['user']->get_Name(); But then I get this error: Can tell me what I have to do, to make this work? Thanks.
  12. That bug is from 2004 I'm currently running php 5.
  13. Hello, I'm getting some errors when binding parameters inside a loop, and it's doing my head in public function query($sql, $params) { if(!$sobj = $this->conn->prepare($sql)) { die('Query Prepare Error (' . $this->conn->mysqli_errno . ') ' . $this->conn->mysqli_error); } else { if(!is_array($params)) { $params = array_slice(func_get_args(), 1); } foreach($params as $value) { $type = strtolower(gettype($value)); $sobj->bind_param($type[0], $this->conn->real_escape_string($value)); } $sobj->execute(); $sobj->bind_result($result); $sobj->fetch(); $sobj->close(); return $result; } } The errors I'm getting is: Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in /nfs/c06/h02/mnt/97387/domains/nickythorne.com/html/v2/includes/classes/class_db2.php on line 67 Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in /nfs/c06/h02/mnt/97387/domains/nickythorne.com/html/v2/includes/classes/class_db2.php on line 67 (Line 67 is $sobj->bind_param($type[0], $this->conn->real_escape_string($value)); above) I'm calling the function like this: $details = new DB(); echo $details->query("SELECT `postcode` FROM `details` WHERE `name` = ? and `address` = ?", array("Josh", "45 Ashdale Road")); Does anyone know how I can solve this? Thanks.
  14. Replace: <a href="#" style="" class="" title=""><img src="button_add_to_cart.gif" width="72px" height="17px" /></a> With: <a href="#" style="" class="" title="" OnClick="alert('Call this number to order');"><img src="button_add_to_cart.gif" width="72px" height="17px" /></a> Hope that helps.
×
×
  • 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.