mysql connection problem!
Moderator: General Moderators
mysql connection problem!
hello,
i've just been installing mysql daemon, it is running nicely, but the problem arises when i'm trying to connect to mysql server using a php script . in myphpinfo() i can see something like
'--with-mysql=shared,/usr', i think that mysql should be supported. when i'm trying to connect i'm always getiing this:
Fatal error: Call to undefined function: mysql_connect() in /usr/local/httpd/htdocs/test.php on line 8.
here is the code i wrote :
<?php
//session_start();
//phpinfo();
$user="root";
$password="nabila";
$database="bouboul";
mysql_connect(localhost,$user,$password);
echo mysql_error();
?>
could anyone tell what is wrong with this ?
thanx
i've just been installing mysql daemon, it is running nicely, but the problem arises when i'm trying to connect to mysql server using a php script . in myphpinfo() i can see something like
'--with-mysql=shared,/usr', i think that mysql should be supported. when i'm trying to connect i'm always getiing this:
Fatal error: Call to undefined function: mysql_connect() in /usr/local/httpd/htdocs/test.php on line 8.
here is the code i wrote :
<?php
//session_start();
//phpinfo();
$user="root";
$password="nabila";
$database="bouboul";
mysql_connect(localhost,$user,$password);
echo mysql_error();
?>
could anyone tell what is wrong with this ?
thanx
well, ur code says :
the problem is, you forgot to add apostraphies around localhost and ur 2 variables....
so, here is the way it should have been written:
note that the '' around ''.$user.'' and ''.$password.'' are 2 apostraphies marks ( ' ). should work fine
last note, don't paste actual username/passwords in here.. for your own security
cheers
Code: Select all
<?php
//session_start();
//phpinfo();
$user="root";
$password="nabila";
$database="bouboul";
mysql_connect(localhost,$user,$password);
echo mysql_error();
?>the problem is, you forgot to add apostraphies around localhost and ur 2 variables....
so, here is the way it should have been written:
Code: Select all
<?php
//session_start();
//phpinfo();
$user="root";
$password="nabila";
$database="bouboul";
mysql_connect('localhost',''.$user.'', ''.$password.'') or die(mysql_error());
?>note that the '' around ''.$user.'' and ''.$password.'' are 2 apostraphies marks ( ' ). should work fine
last note, don't paste actual username/passwords in here.. for your own security
cheers
Fatal error: Call to undefined function: mysql_connect()
the code looked welll,
but My problem is that apache / php is not recognizing my mysql connects. WHen i look in php info i see that it is built --with-mysql . in my php.ini there is a line extension=mysql.so
pleaz help !!
but My problem is that apache / php is not recognizing my mysql connects. WHen i look in php info i see that it is built --with-mysql . in my php.ini there is a line extension=mysql.so
pleaz help !!
well, i'm not really sure what you mean.. could you give me an example? but if you can put the code revision i just posted above in a php script, run it, and it doesn't give you an error, then you are connecting to mysql with no problem... you just gotta figure out what you want to do with that connection at that point..
if you have any error codes, that would help out too
if you have any error codes, that would help out too
i put the code revision you gave me here is the code :
<?php
$user="root";
$password="nabila";
$database="bouboul";
mysql_connect('localhost',$user,$password) or die(mysql_error());
?>
but the problem is that , when i'm tryng to run it i'm always getting the following :
Fatal error: Call to undefined function: mysql_connect() in /usr/local/httpd/htdocs/test.php on line 5.
i think that apache/php are not recognizing mysql functions. mysql daemon is running nicely alone as well as apache/php.
my problem is that i cannot connect to mysql server.
pleaz help
thanx
<?php
$user="root";
$password="nabila";
$database="bouboul";
mysql_connect('localhost',$user,$password) or die(mysql_error());
?>
but the problem is that , when i'm tryng to run it i'm always getting the following :
Fatal error: Call to undefined function: mysql_connect() in /usr/local/httpd/htdocs/test.php on line 5.
i think that apache/php are not recognizing mysql functions. mysql daemon is running nicely alone as well as apache/php.
my problem is that i cannot connect to mysql server.
pleaz help
thanx
try this, see what it returns
Your problem is, you need to store the result of mysql_connect("localhost", $user, $password) somewhere which your weren't doing...i think 
Mark
Code: Select all
<?php
$user="root";
$password="nabila";
$database="bouboul";
$link = mysql_connect("localhost", $user, $password)
or die("Could not connect: " . mysql_error());
print ("Connected successfully");
mysql_close($link);
?>Mark
well, he doesn't actually *have* to put the code in a variable.
he could still call it with
and let mysql close after the script ends.
he could still call it with
Code: Select all
<?php
@mysql_pconnect("localhost", $user, $password) or die(mysql_error());
echo 'we made it';
?>