Question:
PHP programming problem? how to use mysql?
QuestionAnswer
2006-07-06 12:21:41 UTC
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?
Five answers:
2006-07-06 16:10:05 UTC
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());
2006-07-06 13:40:24 UTC
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...



http://localhost/test.php



... or ...



http://127.0.0.1/test.php



The 2nd form works better if you're experimenting with sessions or cookies.
oc_surf
2006-07-10 08:32:33 UTC
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.
Locoluis
2006-07-06 13:27:31 UTC
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.
John J
2006-07-06 13:39:47 UTC
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 http://localhost/phpFile.php


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...