Jump to content

raydona

Members
  • Content Count

    43
  • Joined

  • Last visited

Community Reputation

0 Neutral

About raydona

  • Rank
    Member

Profile Information

  • Gender
    Not Telling
  1. Hi, I'm trying to load an application on unix server but when it does system check I keep on getting following error message and application will not load. Your PHP Version is 5.6.22, but always_populate_raw_post_data = 0. $HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0. This will stop the installer from running. Please open your php.ini file and set always_populate_raw_post_data to -1. If you need more help please call your hosting provider. As suggested by my hosting provider I've created php.ini file and put always_populate_raw_post_data = -1 into file and placed in public_html folder. But it is not solving problem. Any suggestion as to what I should do to solve problem? I'm completely new to all this. All help will be greatly appreciated.
  2. Hello, I want to install a new application on my unix x86_64 (virtual) server. The server has MySQL Version 5.5.49 but the application requires MySQL 5.6 or upwards. I want to update MySQL on my server. I have seen an article where it says: Replace the MySQL version from 5.4.9 with 5.6 in /var/cpanel/cpanel.config file #vi /var/cpanel/cpanel.configand then, change -------"mysql-version=5.4.9" to "mysql-version=5.6". Neither the directory /var/cpanel/cpanel.config nor the file cpanel.config exist on my server. (Also there is no directory \usr.) Do I have to create these manually? If so what do I enter in the .config file? Is there an easier way of upgrading? There are no buttons on my server for upgrading MySql easily as there is for PHP.
  3. Hi, Thanks for your help. Before I try out some of your suggestions can I ask does it make a difference if the collation of the database is "latin1_swedish_ci" while the collation of the table is "utf8_general_ci"? Also I have just discovered that my program works on a remote server with operating system linux but not on a remote server using windows operating system, my program is intended for latter. I still get: The error is now showing only one array. I don't know why it showed two previously?? This problem is beyond me!!
  4. Sorry, in my confusion I did the wrong thing and should have written: public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { print_r($this->_query->errorInfo()); $this->_error = true; } } return $this; } The message I get is: Array ( [0] => 00000 [1] => [2] => ) Array ( [0] => 42S22 [1] => 1054 [2] => Unknown column 'postcode' in 'field list' ) Problem creating an account! Previously it said "Unknown column 'address' in 'field list'". Now it's saying "Unknown column 'postcode' in 'field list' ". There is nothing wrong with the fields in the database. I've checked them a hundred times. There is something wrong with the database. Could this be a problem with the server rather than my coding? Please help?
  5. Hello, Many thanks for your help. I've checked, $sql does contain a valid INSERT sentence. It's both a comparison and an assignment. Whatever is returned by prepare() is assigned to _query and this is tested I've tried the following debugging. public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); print_r($this->_query->errorInfo()); } else //an error has occured in SQL query { $this->_error = true; } } return $this; } The message I get is: I don't how to interpret this error message. Could you please help?
  6. Hi, My program works on WAMP (PHP Version 5.5.12) running on my machine. However, the same program will not run on remote server (PHP Version 5.4.32). Basically, I'm trying to insert values obtained from a form into a database. I've checked and rechecked the table I'm inserting into and I can't find anything wrong with it. The trouble is it's hard to debug a PHP program. Unlike, say, C++ which requires a compiler, you can trace the program line by line to look for errors. That's not possible with PHP and makes it so much harder to look for faults. The relevant functions used to send data to database are shown below. insert() is returning false every time and I can't understand why! I wonder if anyone can suggest where things might be going wrong. I would be very grateful. public function insert($table, $fields = array()) { if(count($fields)) //true if $fields holds data { $keys = array_keys($fields); $values = ''; //to put inside query $x = 1; foreach($fields as $field) { $values .= '?'; if($x < count($fields)) { $values .= ', '; } $x++; } $sql = "INSERT INTO {$table} (`".implode('`, `', $keys) . "`) VALUES({$values})"; if(!$this->query($sql, $fields)->error()) { return true; } } return false; } public function query($sql, $darams = array()) { $this->_error = false; //reset error if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { $this->_error = true; } } return $this; } public function error() { return $this->_error; } public function count() { return $this->_count; }
  7. Hello, I have following function find() in class User: public function find($user = null) { if($user) { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { $this->_data = $data->first(); return true; } } return false; } When line "if($data->count())" is encountered I get following message: Fatal Error: Call to a member function count() on a non-object $data should hold a DB object but doesn't. class User { private $_db; private $_data; private $_sessionName; private $_isLoggedIn; public function __construct($user = null) { $this->_db = DB::getInstance(); .................. Class DB is shown below: class DB { private static $_instance = null; private $_pdo, //PDO object $_query, //last query executed $_error = false, $_results, //store results set of a query $_count = 0; private function __construct() { try { $dsn = sprintf( "mysql:host='';dbname='';", Config::get('mysql/host'), Config::get('mysql/database') ); $this->_pdo = new PDO( $dsn, Config::get('mysql/username'), Config::get('mysql/password')); } catch(PDOException $excp) { die($excp->getMessage()); } } public static function getInstance() { if(!(self::$_instance)): self::$_instance = new self(); endif; return self::$_instance; } public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { $this->_error = true; } } return $this; } public function action($action, $table, $where = array()) { if(count($where) === 3) //field, operator, value { $operators = array('=', '>', '<', '>=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; if(!$this->query($sql, array($value))->error()) { return $this; //no error return $this } } } return false; } public function get($table, $where) { return $this->action('SELECT *', $table, $where); } public function error() { return $this->_error; } public function count() { return $this->_count; } public function results() { return $this->_results; } public function first() { return $this->results()[0]; } I have debugged the program as far as I could. The problem lies in the following function: public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { $this->_error = true; } } return $this; } When line "if($this->_query->execute())" is encountered program does not execute and null is returned. I have taken bits of this function from the internet and have put it together with my code. That's where the problem lies. Is there any way query(), or if need be any other function, can be altered, within context of class DB, so that query() returns an object of class DB which can be used in find()? Will be very grateful for all assistance.
  8. Hi, Many thanks for the replies. I still cannot resolve the problem. I have now included all of the relevant code. The code relating to PDO I got off the internet with which I am not fully conversant. In class User: public function find($user = null) { if($user) //if username is passed, not null { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { $this->_data = $data->first(); return true; } } return false; } In class DB: class DB { private static $_instance = null; private $_pdo, $_query, $_error = false, $_results, $_count = 0; private function __construct() { try { $dsn = sprintf( "mysql:host='';dbname='';", Config::get('mysql/host'), Config::get('mysql/database') ); $this->_pdo = new PDO( $dsn, Config::get('mysql/username'), Config::get('mysql/password')); } catch(PDOException $excp) { die($excp->getMessage()); } } public static function getInstance() { if(!(self::$_instance)): self::$_instance = new self(); endif; return self::$_instance; } public function get($table, $where) { return $this->action('SELECT*', $table, $where); } public function action($action, $table, $where = array()) { if(count($where) === 3) //field, operator, value { $operators = array('=', '>', '<', '>=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; if(!$this->query($sql, array($value))->error()) { return $this; //if not an error return $this } } } return false; //outside of everything return false } public function query($sql, $darams = array()) { $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)) { $x = 1; if(count($darams)) { foreach($darams as $param) { $this->_query->bindValue($x, $param); $x++; } } if($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else //an error has occured in SQL query { $this->_error = true; }
  9. Hi, I have the following class: class User { private $_db; public function __construct($user = null) { $this->_db = DB::getInstance(); ....... } public function find($user = null) { if($user) { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { ......... return true; } } return false; } In class DB I have: public static function getInstance() { if(!(self::$_instance)): self::$_instance = new self(); endif; return self::$_instance; } public function get() in class DB, after processing, returns $this, the single instance of class DB, this is assigned to $data which is then used to invoke public function count(), a member function of class DB. I am getting the following error: Fatal error: Call to a member function count() on a non-object. I would be very grateful if someone can point out my mistake.
×
×
  • 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.