By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Unable to connect to mysql database

cyberking
P: 84
Hi.
I have just started learning PHP along with MySQL.

I am trying to connect to the MySQL DB server but unable to. I have been tryin. Please help. Its urgent cos I shall soon have to work on PHP .

My testing program is as follows :

Expand|Select|Wrap|Line Numbers
  1.  <?php 
  2.  
  3. $si = function_exists('mysqli_connect');
  4. if($si == 1)
  5. {
  6. echo 'MySQL is installed <br />';
  7. }
  8. else
  9. {
  10. echo 'Not able to connect';
  11. }
  12. ?>
  13.  
Please help. I am unable to connect to the MySQL server
Mar 29 '07 #1
Share this Question
Share on Google+
23 Replies


ak1dnar
Expert 100+
P: 1,584
[PHP]function_exists('mysqli_connect');
[/PHP]
mysqli_connect is not the correct function
mysql_connect is the function

remove "i" from the function name
Mar 29 '07 #2

ak1dnar
Expert 100+
P: 1,584
When you post next time please read the posting guidelines.
Please give a proper title to your thread and wrap the coding using tags. because then from this page itself we can read the codings without going for a IDE.
Mar 29 '07 #3

cyberking
P: 84
Yes. Ok I ll Follow the rules from the next time.

But For now, I still am not able to connect. Please see the following statement.

$dbcnx = mysql_connect("localhost","root","my_pass");

This is in the browser gives me a Fatal Error.

Wats the prob. Please help.
Mar 29 '07 #4

ak1dnar
Expert 100+
P: 1,584
Yes. Ok I ll Follow the rules from the next time.

But For now, I still am not able to connect. Please see the following statement.

$dbcnx = mysql_connect("localhost","root","my_pass");

This is in the browser gives me a Fatal Error.

Wats the prob. Please help.
[PHP]$dbcnx = mysql_connect("localhost","root","my_pass");[/PHP]
this line is not in your original post.
I just made the correction of your script.here its checking weather [PHP]mysql_connect[/PHP] is defined or not.

what do you really wanted. post the complete script here.
Mar 29 '07 #5

cyberking
P: 84
[PHP]$dbcnx = mysql_connect("localhost","root","my_pass");[/PHP]
this line is not in your original post.
I just made the correction of your script.here its checking weather [PHP]mysql_connect[/PHP] is defined or not.

what do you really wanted. post the complete script here.
Hi.
Thanks for takin time to help me.

This is my first program where I am tryin to connect to MySQL server. The complete code is as follows:


<?php

$dbcnx = mysql_connect("localhost","root","my_pass");
if ($dbcnx)
{
echo 'Success';
}
else
{
echo ' Unable' ;
}
But I still get the same error.
Fatal Error: Call to undefined function mysql_connect

Thanks in advance
Mar 29 '07 #6

ak1dnar
Expert 100+
P: 1,584
Did you install mysql in your machine. this script is working fine with correct username and password to mysql server witch runs in the same machine.

[PHP]<?php
$dbcnx = mysql_connect("localhost","root","dba");
if ($dbcnx)
{
echo 'Success';
}
else
{
echo ' Unable' ;
}
?>[/PHP]

use [PHP] tags arround your php lines ;)
Mar 29 '07 #7

cyberking
P: 84
Is that So??

Yes I have MySQL, Apache and PHP all installed on my system. But then, why is it not working for me?

Thanks again for tryin to help me
Mar 29 '07 #8

ak1dnar
Expert 100+
P: 1,584
Is that So??

Yes I have MySQL, Apache and PHP all installed on my system. But then, why is it not working for me?

Thanks again for tryin to help me
Do you have phpMyAdmin installed in your system. and what is the O/S.
Mar 29 '07 #9

cyberking
P: 84
I have XP and I don have PhpMyadmin.
Mar 29 '07 #10

ak1dnar
Expert 100+
P: 1,584
I have XP and I don have PhpMyadmin.
download appserv and install it.
remove all your PHP,MySQL,Apache from the system.

give a fresh copy. Appserv is consist of PHP,APACHE,MySQL,phpMyAdmin in a single pack.

once you done try the coding again.
Mar 29 '07 #11

cyberking
P: 84
But do i need phpmyadmin? Is it not possible without it?

Sorry. but the reason why I am asking is because I just installed all the three, mysql, PHP5 and apache. Is there anything that I have to do in the php.ini file. i even added the php_mysql.dll extension in the php.ini
Mar 29 '07 #12

ak1dnar
Expert 100+
P: 1,584
But do i need phpmyadmin? Is it not possible without it?

Sorry. but the reason why I am asking is because I just installed all the three, mysql, PHP5 and apache. Is there anything that I have to do in the php.ini file. i even added the php_mysql.dll extension in the php.ini
You have to put libmysql.dll to Windows dir.
Mar 29 '07 #13

cyberking
P: 84
You have to put libmysql.dll to Windows dir.
I tried doin it. But still without any results, I still get the same error.. please help.
Mar 30 '07 #14

ak1dnar
Expert 100+
P: 1,584
Problem is with your system not in the coding. so it is up to you. here we can help if there is a error in the coding. again we can give the suggestions for up your system.thats it.
Mar 30 '07 #15

cyberking
P: 84
Thanks again for replyin.

Well let me tell you everythin. I have altered my php.ini file.

Uncommented the extension=php_mysql.dll statement
I have the dll files in the system32 directory.
Php works with apache.
The phpinfo() function shows me all the configuration of php.
I am even able to create tables in MySQL, but the prob is when I try to connect to MySQL thru PHP. I have been tryin for nearl 24 hrs now and no success. Thanks for helpin me all the while. Can you suggest somethin..
Mar 30 '07 #16

ak1dnar
Expert 100+
P: 1,584
what are the dlls are available under system32.
Mar 30 '07 #17

cyberking
P: 84
what are the dlls are available under system32.
php_mysql.dll
php_mysqli.dll
libmysql.dll
Mar 30 '07 #18

ak1dnar
Expert 100+
P: 1,584
under Apache httpd file try to find out this line.

LoadModule php5_module D:/AppServ/php5/php5apache2_2.dll


here in my machine php5 and apache2.2 so in your one version number might be changed.

if it not available add it.first do a search in your php directory.

*php*apache*.dll

if it available check the loadmodule line in httpd.
Mar 30 '07 #19

cyberking
P: 84
Thanks again.

But then, as I said I have no problems in viewing php files in my browser. PHP works fie with Apache. I had also modified the LoadModule statement in the httpd.conf file.
Mar 30 '07 #20

ak1dnar
Expert 100+
P: 1,584
Thanks again.

But then, as I said I have no problems in viewing php files in my browser. PHP works fie with Apache. I had also modified the LoadModule statement in the httpd.conf file.
oops I missed that. ok in php.ini check this line.
mysqli.default_port = 3306
Mar 30 '07 #21

cyberking
P: 84
Yes thats the same as what u have mentioned. its 3306. But still cant get it connected
Mar 30 '07 #22

ak1dnar
Expert 100+
P: 1,584
Add the extention line for msqli to ini file and always restart the node other wise changes never work.
extension=php_mysqli.dll
Mar 30 '07 #23

cyberking
P: 84
Yes. I ll do that. Also BTW, if I rollback to php4 will there be chances that I can get it working? Right now I am using PHP5. I have heard that there is no embedded support for MySQL in PHP5. Thanks again
Mar 30 '07 #24

Post your reply

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