anarchoi Posted April 4, 2008 Share Posted April 4, 2008 well here is my situation: i wrote a little script a few days ago on a host that had php4. Now i'm being hosted by a friend with a newer version, php5. I've been messing around with my scripts for a few hours now, trying to figure out why NOTHING is working. So i decided to make a test, i removed all the useless stuff in my scripts and i tryed to echo all rows of the table.... here's the script: <? // DATABASE $server = "localhost"; $user = "qcanarco_phpb1"; $password = "****"; $database = "qcanarco_phpb1"; mysql_connect($server, $user, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); // Query the Database $query = "SELECT * from news2"; $res = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($res)) { $title = $row["title"]; echo $row["title"]; echo $title; echo "tabarnak"; $actif = $row["actif"]; $validation = $row["valide"]; $localisation = $row["localisation"]; } ?> the result is a blank page on the host with php5 BUT everything is working fine on my old host, with php4 the infos for the databases and the tables are correct.. if this can help, here is my table structure on the old host: -- phpMyAdmin SQL Dump -- version 2.9.1 -- http://www.phpmyadmin.net -- -- Serveur: localhost -- Généré le : Jeudi 03 Avril 2008 à 22:28 -- Version du serveur: 4.1.21 -- Version de PHP: 4.4.2 -- -- Base de données: `anarchoi1_phpb1` -- -- -------------------------------------------------------- -- -- Structure de la table `news2` -- CREATE TABLE `news2` ( `id` int(11) NOT NULL auto_increment, `title` text NOT NULL, `date` text NOT NULL, `time` text NOT NULL, `actif` text NOT NULL, `valide` text NOT NULL, `localisation` text NOT NULL, `infos` text NOT NULL, `web` text NOT NULL, `genre` text NOT NULL, `contrib` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=10021 ; -- -- Contenu de la table `news2` -- INSERT INTO `news2` VALUES (10015, 'jhvjhjhvjh', '30.03.08', '1:41 pm', '1', '1', '', '', '', '', ''); INSERT INTO `news2` VALUES (10016, 'anarchoi', '30.03.08', '3:08 pm', '', '1', '', '', '', '', ''); INSERT INTO `news2` VALUES (10020, 'sfgsd', '30.03.08', '8:59 pm', '', '', '', 'fgfdgsdgsdfgsdgsdfgs', 'sgfgsdg', '', 'anarchOi ()'); on the new host: -- phpMyAdmin SQL Dump -- version 2.11.4 -- http://www.phpmyadmin.net -- -- Serveur: localhost -- Généré le : Jeu 03 Avril 2008 à 22:28 -- Version du serveur: 4.1.22 -- Version de PHP: 5.2.3 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Base de données: `qcanarco_phpb1` -- -- -------------------------------------------------------- -- -- Structure de la table `news2` -- CREATE TABLE `news2` ( `id` int(11) NOT NULL auto_increment, `title` text NOT NULL, `date` text NOT NULL, `time` text NOT NULL, `actif` text NOT NULL, `valide` text NOT NULL, `localisation` text NOT NULL, `infos` text NOT NULL, `web` text NOT NULL, `genre` text NOT NULL, `contrib` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=10022 ; -- -- Contenu de la table `news2` -- INSERT INTO `news2` VALUES(10015, 'jhvjhjhvjh', '30.03.08', '1:41 pm', '1', '1', '', '', '', '', ''); INSERT INTO `news2` VALUES(10016, 'anarchoi', '30.03.08', '3:08 pm', '', '1', '', '', '', '', ''); INSERT INTO `news2` VALUES(10020, 'sfgsd', '30.03.08', '8:59 pm', '', '', '', 'fgfdgsdgsdfgsdgsdfgs', 'sgfgsdg', '', 'anarchOi ()'); Link to comment https://forums.phpfreaks.com/topic/99484-my-script-worked-with-php4-but-now-it-doesnt-work-with-php5/ Share on other sites More sharing options...
anarchoi Posted April 4, 2008 Author Share Posted April 4, 2008 edit: nvm forget this, it was an error i still have the problem with my query from the database tho Link to comment https://forums.phpfreaks.com/topic/99484-my-script-worked-with-php4-but-now-it-doesnt-work-with-php5/#findComment-509009 Share on other sites More sharing options...
BillyBoB Posted April 4, 2008 Share Posted April 4, 2008 make a new file on server with code: <?php echo phpinfo(); ?> then give me what that prints if anything. Link to comment https://forums.phpfreaks.com/topic/99484-my-script-worked-with-php4-but-now-it-doesnt-work-with-php5/#findComment-509011 Share on other sites More sharing options...
anarchoi Posted April 4, 2008 Author Share Posted April 4, 2008 ok nevermind, it was a mistake. I can do a simple echo if it's not output from the database! my phpinfo is here: http://www.quebecunderground.net/phpinfo.php Link to comment https://forums.phpfreaks.com/topic/99484-my-script-worked-with-php4-but-now-it-doesnt-work-with-php5/#findComment-509012 Share on other sites More sharing options...
anarchoi Posted April 4, 2008 Author Share Posted April 4, 2008 OH MY GOD i just found the solution this is really dumb..... on my other host i could begin my scripts with <? tag. Now it has to be <?php Link to comment https://forums.phpfreaks.com/topic/99484-my-script-worked-with-php4-but-now-it-doesnt-work-with-php5/#findComment-509014 Share on other sites More sharing options...
PFMaBiSmAd Posted April 4, 2008 Share Posted April 4, 2008 [rant] Php included several lazy-way short cuts, multiple ways of doing the same thing, and things the programming language was automatically doing (often without the ability to turn them off at the user level) that the programmer himself should have been doing, and only when he wanted them - register globals (the most serious built-in security bug introduced in any programming language), short open tags, magic quotes, $_REQUEST, $_GLOBAL, short and long global array names... to name a few. Short open tags was an effort to save typing the letters "php" and "echo" in a page of code. However, because you cannot detect the setting and adjust your code to match, this resulted in two ways of doing the same thing that makes code non-portable between servers with different settings and you won't always have the ability to change the setting before your code runs (varies by web server type and how php is running under that web server, along with if the host has configured the server so that you can change php settings before your script starts.) So, the recommendation is to always use full opening php tags. Even php.net recommends this - NOTE: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags. Too bad php.net did not nip this problem in the bud and eliminate it as soon as it was recognized. Think of all the wasted time with problems like "my code stopped getting parsed because I switched servers." The recommended php.ini settings have short open tags turned off. So this is not really a php4 vs php5 problem, but a bad and depreciated feature that was left turned on for too long after a problem with it was known. [/rant] Link to comment https://forums.phpfreaks.com/topic/99484-my-script-worked-with-php4-but-now-it-doesnt-work-with-php5/#findComment-509026 Share on other sites More sharing options...
rolltidega Posted April 4, 2008 Share Posted April 4, 2008 So do you have to change all <? instances in the code to <?php to make all of it work again? Link to comment https://forums.phpfreaks.com/topic/99484-my-script-worked-with-php4-but-now-it-doesnt-work-with-php5/#findComment-509267 Share on other sites More sharing options...
PFMaBiSmAd Posted April 4, 2008 Share Posted April 4, 2008 If you want it to work no matter which server you put it on or what php.net decides to do in the future (turning the short open tag off by default is usually their first step in deprecating a function so that it can be removed in a future version.) You will also need to change any short-echo tags <?= to <?php echo Link to comment https://forums.phpfreaks.com/topic/99484-my-script-worked-with-php4-but-now-it-doesnt-work-with-php5/#findComment-509319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.