getting php5.2 setup to connect to sql5

I have just installed Apache2.2.3 , php5.2 and mysql 5.
My question is: How do i setup, or need to do to get php5.2 to connect to mysql5.

I am an absolute beginner and really would like to get started in learning so need to get these sorted :)

Is the apache working?

  • Connect to the server and see if you get the default page.

Are you able to parse PHP pages?

  • create a file on your webserver called phpinfo.php
  • in the file put the following: <?php phpinfo(); ?>
  • access the page by going to the server via http and enter the phpinfo.php (i.e. )
  • you should get a detailed list about your php installation.

Is your MySQL Running?

  • This is more system dependent for connecting. I use a Linux system and can connect via multiple methods (MyODBC, mysql command line, phpMyAdmin via web, sqlyog, etc…)
  • Verify that your MySQL server is running. From there it’s a simple matter of providing appropriate credentials to the application to access the intended data by using mysql_connect (see MySQL MyODBC for details)

Yes php5.2 and apache2.2.3 are working fine ,it just i’m learning from a book and when i tried to load this test example in to verify mysql was working all i got was a blank web page

Mysql Connection Test

<?php $connection = mysql_connect ( "localhost", "root", "") or die ( "Sorry - unable to connect to Mysql" ); echo ( "Congratulations - you connected to Mysql" ); ?>

First I would refer you to for info on posting code… It just makes it so much easier to read posts.

Next, you probably want to look at your connection line

$connection = mysql_connect ( “localhost”, “root”, “”)
If this WERE correct that means you would be connecting as the ROOT user with NO PASSWORD… VERY BAD INDEED!!!

I hope that is not the case.

the syntax for the mysql_connect should be (in it’s very basic form)

$connection = mysql_connect ( “Server”, “Username”, “Password”)

Where :
Server is the name of the server you are connecting to. This may be in many forms. If it’s on the machine that you are running PHP from then you can use localhost or you can use a FQDN with port.

Username is the name of the mysql user authorized to connect to the database and that has been previously set up (NOT your login to the system) within the mysql server…

Password is the password supplied to the mysql Username (from above). Not your system password.

Hi there , yes this time i did get something but it was this error :

Fatal error: Call to undefined function mysql_connect() in C:Program FilesApache Software FoundationApache2.2htdocsmysql.php on line 4

can anyone help me here lol

Please post your code EXACTLY as it was is in your mysql.php. I have tried to duplicate the error and cannot. My error (because I used phony credentials) also gave an error on line 7 not 4.

An undefined function leads me to believe that there is a problem in the configuration. The undefined function is usually a result of it not being found. In this case PHP cannot find the function mysql_connect.

On Windows, you will probably have to copy libMySQL.dll from MySQL’s bin folder to a folder in the library path, like C:Windows or such. Then, you will need to enable the php_mysql.dll extension in php.ini.

This should all be documented in the manual under the MySQL extension.

Sponsor our Newsletter | Privacy Policy | Terms of Service