Page 1 of 1
mysql connection problem!
Posted: Thu Nov 06, 2003 1:12 pm
by bouboul
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
Posted: Thu Nov 06, 2003 3:23 pm
by infolock
well, ur code says :
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()
Posted: Fri Nov 07, 2003 12:53 am
by bouboul
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 !!
Posted: Fri Nov 07, 2003 1:00 am
by infolock
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
Posted: Fri Nov 07, 2003 2:29 am
by bouboul
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
Posted: Fri Nov 07, 2003 3:34 am
by JayBird
mysql_connect is a PHP function, not a MySQL function, so your problem isn't with your MySQL setup.
Mark
Posted: Fri Nov 07, 2003 3:38 am
by JayBird
try this, see what it returns
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);
?>
Your problem is, you need to store the result of mysql_connect("localhost", $user, $password) somewhere which your weren't doing...i think
Mark
Posted: Fri Nov 07, 2003 6:24 pm
by infolock
well, he doesn't actually *have* to put the code in a variable.
he could still call it with
Code: Select all
<?php
@mysql_pconnect("localhost", $user, $password) or die(mysql_error());
echo 'we made it';
?>
and let mysql close after the script ends.