Gaia Posted February 18, 2008 Share Posted February 18, 2008 Hi, Not really sure how to direct this certain issue I am having. I built a PHP script that uses OOP on a PHP 5.2.3 environment. It is working fine in that environment. However, once I copied it over a PHP 5.2.5 enviromnet, it doesn't seem to like it. It comes up in IE as Programming Error or Unavailable Page. Does not show any error messages at all either, I even tried setting the error reporting to E_ALL and still no luck. Just hoping for some suggestions on how to pin-point the exact issue. I have been commenting out small pieces of code but it just does not seem to be parsing the classes correctly. Are their any major updates from 5.2.3 to 5.2.5 that may cause issues? Like restrictions on how classes can be used? Thanks in advanced for any info or suggestions anyone has. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 18, 2008 Share Posted February 18, 2008 The only way anyone in a forum would be able to help find a problem or any php version or configuration specific issue would be if you posted your code. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470108 Share on other sites More sharing options...
Gaia Posted February 19, 2008 Author Share Posted February 19, 2008 Yes, however, I was hoping there might be some general suggestions/thoughts of the issue. It is a couple pages of code, so I wasn't sure that posting it all here would be efficient. I will go through it and try to copy/paste the main area's that I think are causing the issues. I am at work so I don't have the code handy. I will update once I have the exact code. Until then, is it possible to initiate a class, within a class? For example, if i have class.one.php and class.two.php. Can I run an 'include' function to include class.one.php in class.two.php and initiate it without problems? I am currently doing that right now, and it works in my environment, but not the other. Was another reason I was curious if there were any PHP updates that perhaps restricted that kind of coding for some reason. I'm not the best at explaining things . Hopefully my code will be of more help. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470150 Share on other sites More sharing options...
Stooney Posted February 19, 2008 Share Posted February 19, 2008 I would suggest to just post it all if you have no clue where it might be. That way people can test it on their servers, which is hard with only partial code. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470156 Share on other sites More sharing options...
PFMaBiSmAd Posted February 19, 2008 Share Posted February 19, 2008 Here are the specific changes and bug fixes - http://www.php.net/ChangeLog-5.php However, it is highly likely that your code is dependent on specific php.ini settings that are present on one server and not the other, such as short open tags or register globals. The quickest way of getting a solution is if you post your code. Posting bits and pieces will just result in a game of twenty guesses, take up a couple of pages on the forum, and take a day or so. Your choice. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470168 Share on other sites More sharing options...
Gaia Posted February 19, 2008 Author Share Posted February 19, 2008 I am still learning OOP, so I am bound to make noobish mistakes. See below: class config { private $config_path = '/home/gaia/public_html/xx/includes/config.php'; // // Get a configuration value from the config file // public function get_config($config_name) { require($this->config_path); $value = $config[$config_name]; return $value; } } I think the private $config_path may be wrong or I need to declare it differently? Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470172 Share on other sites More sharing options...
Stooney Posted February 19, 2008 Share Posted February 19, 2008 I think the private $config_path may be wrong or I need to declare it differently? It's declared correct. If it doesn't seem to be working just try a simple if(file_exists($this->config_path)){ So, what exactly is the problem? Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470254 Share on other sites More sharing options...
Gaia Posted February 19, 2008 Author Share Posted February 19, 2008 The path seems to exist, when I do the following, it works: class config { private $config_path; // // Get a configuration value from the config file // public function get_config($config_name) { require( '/home/gaia/public_html/ae/includes/config.php'); $value = $config[$config_name]; return $value; } } I tried the previous code on another server, and got the following error: Fatal error: config::require() [function.require]: Failed opening required '' (include_path='.:/usr/local/php5/lib/php') in /home/gaia/public_html/xx/classes/class.config.php on line 28 So, it looks like the var isn't being passed into the module for some reason. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470262 Share on other sites More sharing options...
aschk Posted February 19, 2008 Share Posted February 19, 2008 Are you positive that /home/gaia/public_html/ae/includes/config.php exists? Because by the looks of it this is where you are bombing out. It's also rather naughty to rely on your required file supplying your variables into your current context. i.e. from my point of view as another developer I can only GUESS that the $config array comes from the required file. However I DO see your reasoning behind this and I don't have a better way for you to implement this (unless you want to go down the helper class road). Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470356 Share on other sites More sharing options...
Gaia Posted February 19, 2008 Author Share Posted February 19, 2008 I think I corrected the problem. The $config array is in a file called class.config.php. The config vars are in another file called config.php. Hopefully you guys can help me with another issue now, with the same script. I have a form where you can add things to a database, which uses a class called manage::add which is located in class.manage.php. manage::add also uses a var named $db which initiates a PDO connection. $db is declared in a file called common.php. common.php: // // Initiate the database connection // $db = new PDO('mysql:host=localhost;dbname=xx', 'xx', 'xx'); // // Get the class that contains the config info // require_once("classes/class.config.php"); $config = new config(); // // Get the class that controls entries // require_once("classes/class.entries.php"); $entries = new entries(); // // Class the manages deleting, editing, etc // require_once("classes/class.manage.php"); $manage = new manage(); // // Get the session class & start it // require_once("classes/class.session.php"); $session = new session; $session->start(); // // Set default timezone ( PHP 5+ only ) // date_default_timezone_set('GMT'); class.manage.php: class manage extends entries { public $edit_form; // // Add an entry // public function add($post_info=array()) { global $db; // // Make sure there are no blank fields // if ( in_array("",$post_info) ) { echo '<div class="entry">You left a field blank!</div>'; } else { $admin = $post_info['admin']; $admin_ip = $post_info['admin_ip']; $nickname = $post_info['name']; $nick_ip = $post_info['ip']; $date = $post_info['date']; $reason = $post_info['reason']; $action = $post_info['action']; $partial_ip = manage::break_ip($nick_ip); $partial_ip = $partial_ip[0].'.'.$partial_ip[1]; $sql = "SELECT COUNT(*) FROM entries WHERE nickname LIKE '%$nickname%' OR ip LIKE '$partial_ip%' AND deleted = 0"; if ($res = $db->query($sql)) { if ($res->fetchColumn() > 0) { $is_dup = 1; } else { $is_dup = 0; } } $query = $db->prepare("INSERT INTO entries VALUES ('0','$admin', '$admin_ip', '$nickname', '$nick_ip', '$date', '$reason', '$action','','','0','','','','$is_dup')"); $query->execute(); //Send to home page $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'index.php'; header("Location: http://$host$uri/$extra"); exit(); } } ....... some more below, but only concerns the above method When I attempt to submit the form, I get the following error saying that $db is non-object: Fatal error: Call to a member function execute() on a non-object in /home/gaia/public_html/xx/classes/class.manage.php on line 67 I figured setting it as a global $db would allow the use of $db in another file? Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470648 Share on other sites More sharing options...
aschk Posted February 19, 2008 Share Posted February 19, 2008 These are your problem lines: $query = $db->prepare("INSERT INTO entries VALUES ('0','$admin', '$admin_ip', '$nickname', '$nick_ip', '$date', '$reason', '$action','','','0','','','','$is_dup')"); $query->execute(); As you can see you're assigned the prepare statement to your $query variable. BUT then calling execute on the query variable. I think you probably want to do $db->execute() instead. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470654 Share on other sites More sharing options...
Gaia Posted February 19, 2008 Author Share Posted February 19, 2008 But doesn't that defeat the purpose of assigning it to $query? Wouldn't I just do the following and it be the same then? $db->prepare("INSERT INTO entries VALUES ('0','$admin', '$admin_ip', '$nickname', '$nick_ip', '$date', '$reason', '$action','','','0','','','','$is_dup')"); $db->execute(); Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470678 Share on other sites More sharing options...
aschk Posted February 19, 2008 Share Posted February 19, 2008 Yes I imagine so, but then I haven't worked with PDO so I don't know whether the prepare statement returns an object or not That's for you to find out... Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470701 Share on other sites More sharing options...
rhodesa Posted February 19, 2008 Share Posted February 19, 2008 Gaia, your original PHP syntax is correct, but my guess is your SQL is invalid. Try replacing those two lines with this for more debug info: $query = $db->prepare("INSERT INTO entries VALUES ('0','$admin', '$admin_ip', '$nickname', '$nick_ip', '$date', '$reason', '$action','','','0','','','','$is_dup')"); if(!$query){ print "PDO::errorInfo():\n"; print_r($db->errorInfo()); exit; } $query->execute(); Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470717 Share on other sites More sharing options...
duclet Posted February 19, 2008 Share Posted February 19, 2008 It would be strange that it works in 5.2.3 as compared to 5.2.5? If that happens, what I see is a possible different configuration in 5.2.5. Double check to see if the configurations are all the same such as include_path. Check the error logs if no error messages are displayed because the settings might have been set to be written in the error log. You can do the following at the command line: tail -f path_to_error_log then load up the page to see any error messages. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470773 Share on other sites More sharing options...
Gaia Posted February 19, 2008 Author Share Posted February 19, 2008 Hmm, I am getting this error from PDO. As far as i know,no other queries are active... PDO::errorInfo(): Array ( [0] => HY000 [1] => 2014 [2] => Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. ) I have a common.php that initiates the class, and at the end i include footer.php that nulls out $db ( $db=NULL; ). Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-470894 Share on other sites More sharing options...
Gaia Posted February 19, 2008 Author Share Posted February 19, 2008 Couldn't locate the edit button: However, I think it is saying this query was not complete, or closed? $sql = "SELECT COUNT(*) FROM entries WHERE nickname LIKE '%$nickname%' OR ip LIKE '$partial_ip%' AND deleted = 0"; if ($res = $db->query($sql)) { if ($res->fetchColumn() > 0) { $is_dup = 1; } else { $is_dup = 0; } } Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-471006 Share on other sites More sharing options...
rhodesa Posted February 19, 2008 Share Posted February 19, 2008 Try using query() for both, so update these 2 lines: $res = $db->query("INSERT INTO entries VALUES ('0','$admin', '$admin_ip', '$nickname', '$nick_ip', '$date', '$reason', '$action','','','0','','','','$is_dup')"); //$query->execute(); //Remove this if(!$res){ print "PDO::errorInfo():\n"; print_r($db->errorInfo()); exit; } Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-471016 Share on other sites More sharing options...
Gaia Posted February 19, 2008 Author Share Posted February 19, 2008 Hmm, still getting the same error message. I really don't know why this is being so problematic. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-471187 Share on other sites More sharing options...
rhodesa Posted February 20, 2008 Share Posted February 20, 2008 Sorry I can't be more help...I've never used the PDO module before. Everything I am suggesting is stuff I read off the php.net site. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-471287 Share on other sites More sharing options...
aschk Posted February 20, 2008 Share Posted February 20, 2008 It might have something to do with performing 1 query , not reaching the end of the resultset and then performing a 2nd query and then trying to loop through the resultset. At least this is the impression i'm getting from reading the last few posts. As the error message suggests you should be performing your $db->query($sql) with an additional parameter, e.g. $db->query($sql, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY). Lookup PDO and find the related constants you can use. Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-471590 Share on other sites More sharing options...
Gaia Posted February 23, 2008 Author Share Posted February 23, 2008 I think the issues I am having are due to the following code: $sql = "SELECT COUNT(*) FROM entries WHERE nickname LIKE '%$nickname%' OR ip LIKE '$partial_ip%' AND deleted = 0"; if ($res = $db->query($sql)) { if ($res->fetchColumn() > 0) { $is_dup = 1; } else { $is_dup = 0; } } When I attempt to re-build it using the example from PHP.NET docs, I get an error: $sql = "SELECT COUNT(*) FROM entries WHERE nickname LIKE '%$nickname%' OR ip LIKE '$partial_ip%' AND deleted = 0"; if ($res = $db->query($sql)) { // Check the number of rows that match the SELECT statement if ($res->fetchSingle() > 0) { echo 'Entries found'; } // No rows matched -- do something else else { print "No rows matched the query."; } } Error: Fatal error: Call to undefined method PDOStatement::fetchSingle() in /home/gaia/public_html/xx/classes/class.manage.php on line 55 I am taking this directly from the PHP docs, so why would it not work? Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-474769 Share on other sites More sharing options...
aschk Posted February 25, 2008 Share Posted February 25, 2008 Which PHP Docs are you using? Because I can't find fetchSingle() http://uk3.php.net/manual/en/function.PDOStatement-fetch.php Try: <?php $row = $res->fetch( PDO::FETCH_NUM ); if($row[0] > 0){ // more than 1 row fits our query. // this does a test on COUNT(*) which should return the number of records. } ?> Link to comment https://forums.phpfreaks.com/topic/91785-classes-php-versions/#findComment-475678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.