Forum Moderators: travelin cat

Message Too Old, No Replies

Mac OS X, PHP 4.3.4, MySQL 4 Conflict ...

Conflict with PHP and MySQL, php pgs not accessing MySQL data correctly

         

bubone2

11:23 pm on Oct 29, 2004 (gmt 0)

10+ Year Member



Hello,

I am a webmaster at a school district, primarily mac environment, and I do a lot of php/mysql web development. I develop on a mac OS X 10.2.8 ibook, and post to a mac OS X 10.2.8 G4 server. The server has MySQL 4 running and I just installed PHP 4.3.4 (from 4.1.2).

Before I upgraded the php, all but one of my pages worked correctly (posting queried data appropriately). The one page that didn't display correctly was an import code that pulled data from a comma delimited file into a mysql database. I found out on www.php.net that the function I was using fgetcsv requires auto_detect_line_endings to be set to ON in the php.ini file. However, I could not locate the php.ini file to edit, so I decided to upgrade the php version in hopes that the file would be recreated.

So, I upgraded to PHP 4.3.4, and now about half of my pages do not post mysql queries as they did before. For instance, I have a login page which checks the user input against the database. However, now it appears as though it cannot access the database data because no users can be found by the login script. The database HAS NOT changed. The only change was the php upgrade.

I have other pages experiencing the same problem. The page connects to the MySQL database. I know this because it does not return a connection failure (neitehr built-in error/warnings, nor my own failure error messages). However, whenever I use a submit button to run an sql query, nothing posts. It appears to me as though it is somehow not able to get the data which resides in the database. And it is NOT a MySQL query problem or other programming problem. I know that because before the upgrade, all pages (with the exception of that one import pg) worked perfectly and nothing else has changed.

If you have an idea as to why I am experiencing this problem, I would appreciate any help you can give me. Ideas on PHP and MySQL version conflicts?

Thx,
Josh

BjarneDM

10:32 pm on Nov 2, 2004 (gmt 0)

10+ Year Member



I've had a simliar problem where using localhost didn't work in php after upgrading MySQL. The problem was (and is) that php no longer could/can access the mysql socket. My solution was to use the tcp/ip interface instead and replace localhost with 127.0.0.1:3306

this is my php database connection script (suitably anonymised):
<?php

$host = '127.0.0.1:3306' ;
$user = 'user' ;
$password = 'password' ;

$dbcnx = mysql_connect($host,$user,$password) ;
if (!$dbcnx )
{
echo ('fejlede at connecte til serveren<br>'.mysql_error());
exit() ;
}
else
{
// echo('fik forbindelse til serveren<br>');
}

$base = mysql_select_db('database',$dbcnx) ;
if (!$base )
{
echo('fejlede at connecte til databasen<br>'.mysql_error());
exit() ;
}
else
{
// echo('fik forbindelse til databasen<br>');
}

?>

This script will also give you exactly where and what goes wrong when connecting to you MySQL database

dcrombie

10:40 am on Nov 3, 2004 (gmt 0)



The problem is probably that the new PHP has register_globals set to off by default. You can either: turn it on (in httpd.conf or .htaccess); or use $_POST["varname"] to access POST variables instead of just $varname.

coopster

1:05 pm on Nov 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, bubone2.

I'd like to believe that dcrombie is spot-on here. Using Register Globals [php.net] went from ON to OFF in PHP 4.2.0. You didn't mention whether or not you are running Apache, but a quick per-directory override setting will let you know immediately if this is your issue. Have a look at Clarification of Global Variables OFF [webmasterworld.com] and the linked threads within for more information.

BjarneDM

1:08 pm on Nov 3, 2004 (gmt 0)

10+ Year Member



register_globals & php.ini

If there's an excisting php.ini does it then get overwritten / updated? I can see that the upgrade is from a version of php from before they got turned off by default.

register_globals has been turned off for a good reason: it's a security hole to have them turned on - it's possible to modify variables on the server by sending suitably crafted http headers.

coopster

1:15 pm on Nov 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The existing php.ini may get overwritten, it really depends on how you do the install/upgrade (installers, etc). I don't use installers, I prefer to control this myself. On any given upgrade I will use the new version of php.ini as a starting point and change the directives to fit my preferences, usually by reviewing my last saved copy from the previous version -- it's hard to remember everything ;) Also, any new release usually has a few new directives to be considered during installation and configuration and I want to be sure to review them during setup.

dcrombie

1:39 pm on Nov 3, 2004 (gmt 0)



The Darwin (Mac OSX) installation is a bit different in that it doesn't have a php.ini file by default. You can achieve the same effect in
/etc/httpd/httpd.conf
by adding some lines at the end of the file:

<IfModule mod_php4.c> 
php_admin_flag register_globals on
</IfModule>

(I set a bunch of other flags at the same time but that's the one for this problem)

coopster

2:57 pm on Nov 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Or, when running an OS X Server [php.net] installation, you can copy and rename the
php.ini-dist
file to your bin directory from your PHP source directory:
cp php.ini-dist /usr/local/bin/php.ini 
# or (if your don't have a local directory):
cp php.ini-dist /usr/bin/php.ini

bubone2

8:10 pm on Nov 3, 2004 (gmt 0)

10+ Year Member



Thank you for all of your responses to my topic. As it turns out dcrombie was exactly right, the problem was with the POST variables. I have been able to resolve this issue now.

The pages in which I was experiencing some problems were all forms which relied on a large number of text inputs (textboxes, select drop downs, check boxes).

With the upgrade (from PHP 4.1.2 to 4.3.4) there have been some important changes. Specific to my issue, it has become necessary to explicitly retrieve the POST variables for use upon submitting the form. This is done in the following way:

Text Input: <input type=text name=MYINPUT>
Submit: <input type=submit name=SUBMIT_FORM value=Submit Form>
---
$MYINPUT = $_POST['MYINPUT'];
$SUBMIT_FORM = $_POST['SUBMIT_FORM'];

Then because we have retrieved this post data we can use it. I then go ahead and input that data into a database.

This appears to have solved my problem. This looks like a good forum community that I will keep my eye on. Thanks for your help.

coopster

2:23 am on Nov 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Great. And nice catch, dcrombie.