phpvox Posted June 18, 2007 Share Posted June 18, 2007 how can i make the below code compatble with PHP5.......this works fine with php4......what changed in php5 that it cant connect to database anymore ? thanks <? $connected = false; function c() { global $db_host, $db_login, $db_pswd; $db = @mysql_connect($db_host, $db_login, $db_pswd); $connected = true; return $db; } function q($q_str) { global $db_name, $connected; if(!$connected) { c(); } $r = mysql($db_name, $q_str); return $r; } function d($db) { @mysql_close($db); } function e($r) { if(@mysql_numrows($r)) return 0; else return 1; } function f($r){ return @mysql_fetch_array($r); } function nr($r){ return @mysql_num_rows($r); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted June 18, 2007 Share Posted June 18, 2007 what changed in php5 that it cant connect to database anymore ? Nothing, the code is just poorly written in the first place. Remove all the @'s for starters, lets see if you can get an actual error so we can see whats going on. Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 18, 2007 Share Posted June 18, 2007 There were no changes made that would cause such a thing. I believe the problem lies elsewhere. Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 19, 2007 Author Share Posted June 19, 2007 i tried it, nothing happened Quote Link to comment Share on other sites More sharing options...
trq Posted June 19, 2007 Share Posted June 19, 2007 Have you tried using <?php instead of just <? ? That changed long before php5. Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 php 4 will run at php 5 but php5 wont run in some case in php 4 Quote Link to comment Share on other sites More sharing options...
DJTim666 Posted June 19, 2007 Share Posted June 19, 2007 Have you tried using <?php instead of just <? ? That changed long before php5. Not necessarily. As long as his hosting service has short tags enabled he will be able to use <? code ?>. But yes, using <?php code ?> may fix the problem. Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 <?php code ?> vs <? code ?> <? code ?> = this thing got prob because of the xml i think cause it uses also that tags but in the localhost this will run if pure php is used Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 19, 2007 Author Share Posted June 19, 2007 yes i have a conf.xml file containing the database info Quote Link to comment Share on other sites More sharing options...
trq Posted June 19, 2007 Share Posted June 19, 2007 I'll ask again. Have you tried using <?php instead of just <? ? Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 19, 2007 Author Share Posted June 19, 2007 sorry thorpe, im a newbie....do u mined telling me how to do that ? thanks Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 19, 2007 Share Posted June 19, 2007 I guess a better question is. What exactly is your script doing on PHP5? Is it just showing you your PHP code? If so then Thorpe's suggestion should work, otherwise, we'll need to know more about the problem, like what exactly do you get when you run the script? Quote Link to comment Share on other sites More sharing options...
milo.desert Posted June 19, 2007 Share Posted June 19, 2007 edit your 'php.ini' file, find 'short_open_tag = Off' and 'asp_tags = Off' those words, change 'Off' to 'On', restart server. Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 19, 2007 Author Share Posted June 19, 2007 I havent done anything yet, but this is the problem: Warning: mysql() [function.mysql]: Access denied for user 'apache'@'localhost' (using password: NO) this is not due to incorrect database info.....the info is correct, this is a compatibility issue from PHP4 to PHP5 I can downgrade to php4 in ONE click from the cpanel, and it works fine but when i click on using PHP5...then i get the above error please dont post telling me to check database info, because it is correct....... something has changed in PHP5 that the script dosent connect to database. this only happenes when i upgrade to php5 >: thanks Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 19, 2007 Share Posted June 19, 2007 Umm... I see your problem. You should never use the mysql() function. I couldn't really find any information on it but it seems to use some sort of default configuration to connect to your database which may have been ignored in PHP4 but used in PHP5. Always use mysql_query() for executing queries in mysql. Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 19, 2007 Author Share Posted June 19, 2007 thanks for ur replay..........but i didnt write the code, i bought this script, and the company went down, so i cant get any tech support from them, the script is encoded except that the code i showed you ....so what should i do now ? Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 19, 2007 Share Posted June 19, 2007 A quick fix would be: mysql_db_query($db_name, $q_str); instead of: mysqldb_name, $q_str); Although, I would recommend a lot of restructuring . Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 19, 2007 Author Share Posted June 19, 2007 it didnt work.....thats okay i might let this script go then, cause i have to be on php5. but thank you guys for trying...cheers Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 20, 2007 Author Share Posted June 20, 2007 okay what about this code, i found this in a diffrent folder <? function c () { global $db_host; global $db_login; global $db_pswd; $db = @mysql_connect ($db_host, $db_login, $db_pswd); $connected = true; return $db; } function q ($q_str) { global $db_name; global $connected; global $query_count; global $show_debug_info; global $queries_str; if (!$connected) { c (); } $r = mysql ($db_name, $q_str); if ((ee () AND $show_debug_info)) { echo '' . ': ' . $q_str; } if (!$query_count) { $query_count = 0; } $queries_str .= '' . $q_str . '<br />'; ++$query_count; return $r; } function d ($db) { @mysql_close ($db); } function e ($r) { if (@mysql_numrows ($r)) { return 0; } else { return 1; } } function ee () { global $show_debug_info; $err = mysql_error (); if ($show_debug_info) { echo $err; } return ($err ? true : false); } function f ($r) { return @mysql_fetch_array ($r); } function fr ($r) { return @mysql_fetch_row ($r); } function nr ($r) { return @mysql_num_rows ($r); } $connected = false; ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 20, 2007 Share Posted June 20, 2007 and what do mean with that code ? are you asking for comment or .. ? ASTIG!! Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 20, 2007 Share Posted June 20, 2007 Same problem: $r = mysql ($db_name, $q_str); Should be: $r = mysql_db_query ($db_name, $q_str); if that doesn't work then just try: <?php function c() { global $db_host; global $db_login; global $db_pswd; global $connected; static $db; if(!$connected){ $db = @ mysql_connect($db_host, $db_login, $db_pswd); $connected = true; } return $db; } function q($q_str) { global $db_name; global $connected; global $query_count; global $show_debug_info; global $queries_str; $db = c(); $r = mysql($db_name, $q_str, $db); if ((ee() AND $show_debug_info)) { echo '' . ': ' . $q_str; } if (!$query_count) { $query_count = 0; } $queries_str .= '' . $q_str . ' '; ++ $query_count; return $r; } ?> Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 20, 2007 Author Share Posted June 20, 2007 it didnt work Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 20, 2007 Share Posted June 20, 2007 Err... crap ... forgot to change one more line in the code... heh... guess that's what I get for not testing it . Change this: $r = mysql($db_name, $q_str, $db); To this: $r = mysql_db_query($db_name, $q_str, $db); In the code that I gave you as an alternative solution. Quote Link to comment Share on other sites More sharing options...
phpvox Posted June 20, 2007 Author Share Posted June 20, 2007 yeah same thing....no good >: thanks anyways Quote Link to comment Share on other sites More sharing options...
trq Posted June 20, 2007 Share Posted June 20, 2007 That code is riddled with bugs. php4 or 5. There is no such function as mysql_numrows, or mysql. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.