473,383 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

connecting to MYSQL using PHP and Apache

15
I trying to configure PHP to run MYSQL and it isn't working. I've spend many hours trying to figure this out. I've made changes to the php.ini file and the httpd.conf file and it no longer gives me an error, but it still doesn't connect to the database. It gets to right before the mysql_connect statement where it says "about to connect", and then instead of the error message, I get nothing. It just sits there.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  
  3. <html>
  4. <head>
  5. <title>Insert to Database</title>
  6. </head>
  7. <body>
  8.  
  9.  
  10. <?php
  11.  
  12. $username = "root";
  13. $password = "krustyrules";
  14. $database = "mysql";
  15.  
  16. echo 'about to connect';
  17.  
  18. $link = mysql_connect("localhost:3306",$username,$password);
  19.  
  20. if(!$link) {
  21.       die('Could not connect: ' . mysql_error());
  22. }
  23. echo 'Connected Successfully';
  24. mysql_select_db($database) or die( "Unable to select database");
  25.  
  26. $firstname = $_POST["fname"];
  27. $lastname = $_POST["lname"];
  28. $emailadd = $_POST["email"];
  29.  
  30. $query = "INSERT INTO contacts VALUES ('',$firstname, $lastname, $emailadd)";
  31.  
  32. mysql_query($query);
  33.  
  34. mysql_close($link);
  35.  
  36. ?><br />
  37. You are <?php echo $_POST["fname"]; ?>.<br/>
  38.  
  39. </body>
  40. </html>
  41.  
  42.  
Jun 17 '07 #1
11 1671
Atli
5,058 Expert 4TB
Have you checked the output of the phpinfo() function for the MySQL info?
Jun 18 '07 #2
jpk872
15
yes nothing there. could it be because I have windows XP and the phpinfo says I have windows NT???
Jun 18 '07 #3
Atli
5,058 Expert 4TB
No, Windows XP uses the NT kernel, so that's all normal.

Make sure you've done all the following:
  • Remove the ; from the line ';extension=php_mysql.dll' in php.ini
  • Add the file 'libmysql.dll', from your PHP root dir, to the PATH enviroment variable. Or just copy the file to your windows directory.
  • Restart the apache server.

If thats all complete MySQL should work.
Jun 18 '07 #4
jpk872
15
it still doesn't work......any suggestions?
Jun 18 '07 #5
Atli
5,058 Expert 4TB
Are you sure the MySQL server is running ok?

You can also try to follow the three steppes I posted earlyer, but this time add the line, 'extension=php_mysqli.dll' and copyt the file 'libmysqli.dll' to your windows dir.
Jun 18 '07 #6
jpk872
15
i've tried the three previous steps before, they didn't work. could it have anything to do with apache? when i test apache i get the screen "It works!", is that right or should i get the other screen?
Jun 18 '07 #7
Atli
5,058 Expert 4TB
That is the default screen apache puts up when it has been successfully installed. The apache setup should not have anything to do with MySQL. MySQL is loaded by PHP.

Try to following code and see what happens.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   echo mysql_connect("localhost", "root", "YOURPWHERE");
  3. ?>
  4.  
If MySQL works, this should print "resource# 1", or something similar. Else, is should print a message telling you that the mysql_connect function is invalid.

If something else happens, it is likely that the PHP connection to MySQL works, but that there is a problem with the MySQL server itself.

In any case, copy the output and show us.
Jun 18 '07 #8
jpk872
15
It shows a blank screen and "done" in the status bar. nothing on the screen at all. I have MySQL Administrator on and it says that MySQL server is running. I also print out the phpinfo page and there is nothing with MySQL on there either.




That is the default screen apache puts up when it has been successfully installed. The apache setup should not have anything to do with MySQL. MySQL is loaded by PHP.

Try to following code and see what happens.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   echo mysql_connect("localhost", "root", "YOURPWHERE");
  3. ?>
  4.  
If MySQL works, this should print "resource# 1", or something similar. Else, is should print a message telling you that the mysql_connect function is invalid.

If something else happens, it is likely that the PHP connection to MySQL works, but that there is a problem with the MySQL server itself.

In any case, copy the output and show us.
Jun 18 '07 #9
Atli
5,058 Expert 4TB
Ok, try this.
Find the line "extension_dir" in your php.ini and point it to the 'ext' directory in your PHP install dir. (In my case 'D:\Program Files\PHP\ext\')
And then restart you Apache server.

Then create a .php file containing the following, and run it.
If everything works you should get a resource #, if not give us the error.
Expand|Select|Wrap|Line Numbers
  1. error_reporting(E_ALL);
  2. echo mysql_connect("localhost", "root", "ROOTPWD") or die(mysql_error());
  3.  
Jun 19 '07 #10
jpk872
15
Got it!!!! Thanks a lot! I didn't have the php.ini file in the C:\Windows dir. I also specified the location of the php.ini file in apache htppd.conf.
Jun 20 '07 #11
Atli
5,058 Expert 4TB
Got it!!!! Thanks a lot! I didn't have the php.ini file in the C:\Windows dir. I also specified the location of the php.ini file in apache htppd.conf.
Ahh ok, glad it worked out.
Jun 20 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Trautman | last post by:
I have installed MySql on a Windows 98 workstation. I start the service with the command: mysqld I can connect to the database and see tables, etc. I have installed Apache Ver 1.X with PHP...
2
by: pancho | last post by:
Greetings, I need help configuring/building PHP3 with MySQL as a DSO on a Solaris 8 box - this module is needed to host some existing sites I will be migrating Note. I built PHP4 from source and...
0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
0
by: bruce | last post by:
Hi... A mysql/Apache issue: I get the following when I'm trying to run a test web site on an Apache 2.0/RH8.0 setup. -------------------------------- Warning: Access denied for user:...
0
by: bruce | last post by:
Hi... Update.... We have the following setup in our httpd.conf file. We've tried to give what's related to the issue. We're trying to set up a virtual host for a test project. The behavior...
6
by: MBS | last post by:
Yeah, read the previous posts...I did that. None answer my question. I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few days ago on WinXP SP2. My goal is to learn to use these...
2
by: news | last post by:
We currently have our mySQL server on the same box as the Apache server. For security and load balancing, we're going to be moving the mySQL server to another box. We're already using a single...
1
by: ironcito | last post by:
Hello, I installed Apache 2.0.55, PHP 5.1.1, and MySQL 5.0.17 (in that order, on Windows XP). I have managed to get Apache and PHP working right, and MySQL by itself seems ok too. However, when...
11
by: Howard | last post by:
Hi, I have been racking my brain trying to figure out what I am missing trying to follow this book to get a php script to work. I would really appreciate if someone could point out my errors....
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.