barry6628 Posted July 13, 2007 Share Posted July 13, 2007 I have a Widows XP Pro system tring to use PHP and MySQL 5 with Apache Server. The Apache seems ok as I use it with Dreamweaver, PHP works OK, MySQL 5 Works from the command line. When I run a simple connection script I get left wih a blank browser as if nothing is happening. I have run phpinfo.php and mysql is listed. I have checked that both Apache and mysql sevises are running and as you can gess ive tried alsort still no luck. Can you help. Regards Barry Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 13, 2007 Share Posted July 13, 2007 What gets displayed when you turn display_errors on within the php.ini (make sure you restart Apache for new changes to take affect). Re run your script again. If there is a problem with script PHP should display an error to the screen rather than a blank screen. Also can you post your code here too. Quote Link to comment Share on other sites More sharing options...
barry6628 Posted July 14, 2007 Author Share Posted July 14, 2007 Hi and thaks for you contact. Im convince the problem is the way im tring to use php to connect to mysql last night i tried using command line prompt and eventulay came up with this. c:\Programe Files\mysql\mysql server5\bin> Then I typed mysql -u barry@localhost root mysql This opend all the variables. How do i change this so i can write php to connect with mysql. I would post you the code i used but ive changed it so much its now a mess. I copied straight out of the book Beginning PHP and MySQL 5 and I tried loads of codes of the net. Time to start again I think. Hope this dosent put you off helping me. Regards Barry Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 14, 2007 Share Posted July 14, 2007 In your php script you can use the various mysql_* functions for working with MySQL databases in PHP. You don't need to use command line in php scripts. For example you use mysql_connect to connect to MYSQL server. mysql_query to run an sql query. I would recommend you to go through the tutorials over at php-mysql-tutorial.com/ for learning how to use PHP with MySQL. NOTE: If you are using PHP5 then you'll need to configure PHP to use the MySQL extension. You can do this by reading this FAQ. Quote Link to comment Share on other sites More sharing options...
barry6628 Posted July 14, 2007 Author Share Posted July 14, 2007 Hi sorry for confusing the issue. i was only using the command prompt to prove mysql was working this is the bit of code I use and it reports cannot connect to server <?php mysql_connect("localhost","barrymd@localhost","24086628") or die("Could not connect to server!"); echo "connected<br />"; @mysql_select_db("books") or die( "Unable to select database"); echo "selected db"; $query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')"; mysql_query($query); mysql_close(); echo "all done"; ?> regards and many thanks for your time so far. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 14, 2007 Share Posted July 14, 2007 Rather than displaying 'Could not connect to server!' when the connection fails place the mysql_error() function within the die statement too. That way you get an error from mysql which which will tell what is wrong New code: <?php mysql_connect("localhost","barrymd@localhost","24086628") or die("Could not connect to server:<br />" . mysql_error()); echo "connected"; mysql_select_db("books") or die( "Unable to select database:<br />" . mysql_error()); echo "selected db"; $query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$email','$web')"; mysql_query($query) or die( "Unable to run query (<tt>$query</tt>:<br />" . mysql_error()); mysql_close(); echo "all done"; ?> Quote Link to comment Share on other sites More sharing options...
barry6628 Posted July 14, 2007 Author Share Posted July 14, 2007 Hi will this help us get to the bottom of the problem! Access denied for user 'SYSTEM'@'localhost' (using password: NO) Regards and again its nice to get help after pulling out your hair. Quote Link to comment Share on other sites More sharing options...
barry6628 Posted July 20, 2007 Author Share Posted July 20, 2007 Hi I dont think you got my last reply I attached my php.ini so ill send it again just imn case. Regards Barry [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 20, 2007 Share Posted July 20, 2007 Your php.ini is fine. just tried on my local install of AMP and Apache started up with no errors, however I did modify the extension_dir line from C:/php5/ext (which your path) to C:/Server/php/ext (which is my path). I'm not sure what to suggest. Looks like everything is setup correctly. however for some reason PHP is ignoring the username/password credentials you have set up within the mysql connect function and tying to connect to mysql with the username 'SYSTEM'. EDIT. Oh hang on. It is to do with your php.ini. when I use mysq_connect with my username/password credentials I get the same error as you are getting. However If I swap your php.ini with my php.ini I connect to mysql fine. EDIT2: Ohh! I think I just solved it. You had a setting called sql.safe_mode on within the php.ini. When you enable this setting PHP will ignore any username/password credentials you use with in mysql_connect function and this is why you are getting the error message. Turn that setting off and you shouldn't get that error message again. Quote Link to comment Share on other sites More sharing options...
barry6628 Posted July 21, 2007 Author Share Posted July 21, 2007 Hi Thanks but no such luck I turned tha off restarted Apache and still the same. Please dont give up on me I do need this. Im loading a laptop see if that will work and then find the difference. Regards Barry Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 21, 2007 Share Posted July 21, 2007 Are you sure php is reading the php.ini you are editing. You can check this by running phpinfo() function within a php script then looking for the line that starts with Loaded Configuration File. This line should show the full path to the php.ini PHP is loading for it's configuration. Is the path stated the same path to the php.ini you are editing? NOTE: If you don't get a Loaded Configuration File line then look for a line that starts with Configuration File (php.ini) Path instead. Quote Link to comment Share on other sites More sharing options...
barry6628 Posted July 22, 2007 Author Share Posted July 22, 2007 Hi tanks for all your help Ive don it. It was a ; after C\php in the environmental variable. Regards Barry 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.