| PHP programming problem? how to use mysql?

PHP programming problem? how to use mysql?

wayiran asked the question:


I have installed:
1- Windows XP
2- Wamp
3- Apache
4- MySQL
5- PHP
6- phpExpertEditor

When I run any php file in phpExpertEditor it works ok,
but when I try to connect php to mysql Im getting Error:

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\PHP Expert Editor\php3A.tmp on line 9

the php code is:



$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>

I asked this question previously and someone said to check I checked it but mysql wasnt there.

=================================

my second question is that i can not run any php file (which is on my HardDisk) by my InternetExplorer !!
I have to upload them to my host (which supports php) and then only i can run them.
Is there any problem in Installation of PHP?
I didnt install Apache,Php,MySQL seperately!
I just installed WAMP which contains them, does it need any arrangement?
I could open file by my IE < http://localhost/test1.php > So i got the answer of my second question.

but still i cant run a php file which is trying to connect to mysql !? i get this error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘peter’@'localhost’ (using password: YES) in C:\wamp\www\bb.php on line 4
Could not connect: Access denied for user ‘peter’@'localhost’ (using password: YES)

and this is code of php file:


$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>

It seems that problem is in connection of php to mysql, but i have activated mysql by wamp…

Related posts:

  1. How do I get my PHP program to connect with MySQL? SYSV1RUS asked the question: In datasource I use myodbc.dll in...
  2. How to start programming with PHP on my computer? polo_player13 asked the question: I downloaded WAMP and I set...
  3. How can I make sure that my customers don’t remove my copyright from my PHP program? havenomercy3 asked the question: I wrote a PHP program and...
  4. What is the best tutorial website to learn PHP and MySQL programming? Dr. Bill Fine asked the question: I program in SQL...
  5. What is HTTPs and do I need to change my PHP program to work with it? mesh2005 asked the question: I have a PHP program that...

Filed Under Programming & Design |

Tagged With , ,

Comments

5 Responses to “PHP programming problem? how to use mysql?”

  1. Locoluis on April 28th, 2008 5:15 pm

    You problem is that your PHP installation doesn’t have support for MySQL.

    Look for a line that reads:

    ;extension=mysql.ddl

    delete that ; so it reads:

    extension=mysql.ddl

    Then restart your web server
    .
    Also, you may want to check the extension_dir in your php.ini .

    No, you can’t run a php file in Internet Explorer. What appears in your browser when you point it to a php file in your host is the HTML output from the php program. Your webserver is the one that runs the php program, takes its output and sends it to your browser. Your browser only sees the HTML output.

  2. John J on April 30th, 2008 8:01 pm

    For your second question, if you have apache running on your local system, copy your php files to the document root of apache and use IE to go to

  3. gruumsh on May 3rd, 2008 11:06 am

    Create a simple file, let’s call it “test.php”

    In that file, have a line like this…

    Put it in a public directory on your server, and check out the statistics. If there is no information reported on the MySQL version and settings, then it definitely isn’t enabled in your PHP executable.

    Note: if the test file we just created is in a public place on your server, you’ll want to delete it when you’re through. Otherwise you’re giving hackers a bunch of useful information about your server.

    If it’s NOT enabled, then the solution will depend on what version of PHP. The 2nd link below goes into detail.

    For the 2nd question, it depends on how you’re running the file. It sounds like you’re trying to open the file directly via the file system. However since you appear to have Apache installed, you CAN run the PHP locally as long as it’s in the folder that is available to the Apache server. For example, if you’re using the default of…

    c:\Apache2\htdocs

    Then if you put the file “test.php” in the the above folder, the way you would point your web browser at the file is…

    … or …

    The 2nd form works better if you’re experimenting with sessions or cookies.

  4. dhvrm on May 5th, 2008 1:18 am

    First, you should use mysql_pconnect, not mysql_connect, as mysql_pconnect is both recommended by Zend (the makers of PHP) and persists the connection for you, reducing load on the server.

    Next, the user name and password you supply to connect to the MySQL database need to be the user name and password you assigned when creating the MySQL database. When you set up MySQL, you had to create a user and a password. Those are the values you should be supplying as arguments.

    So, let’s assume the following is true of your MySQL installation:

    1. You are running it under the localhost (probably true);
    2. Your MySQL user name is peter;
    3. Your MySQL password is password

    In that case, this should work:

    $con = mysql_pconnect( “localhost”, “peter”, “password” ) or die( mysql_error());

  5. oc_surf on May 7th, 2008 2:04 pm

    Repying to dhvrm’s comment. You should not use mysql_pconnect instead of mysql_connect. mysql_pconnect causes apache to create a new and constant connect to mysql the entire time the user is on your website. It will increase server and database load. You should connect to the database and release it as soon as you’re done.

    Plus, If you have limited mysql to only 50 connects this means only 50 people could use your website at once. Instead of 50 connections to the database at once.