Page 1 of 1

Newbie basic (?) problem with mysql_connect()

Posted: Sat Jan 04, 2003 10:09 am
by bawen
Runs PHP 4.2.2, Apache 2.0.40 in a RedHat 8.0 system and it works fine. Now I have tried to connect to MYSQL and failed with the response

Fatal error: Call to undefined function: mysql_connect() in .../s.php on line 2

mysql works fine from mysql client but somehow not from PHP and Apache

my test script likes

Code: Select all

<?php
$link=mysql_connect("localhost","user","passw");
$query="Select * from mytab";
$tot_data=mysql_db_query("mydb",$query,$link);
while ($row=mysql_fetch_array($tot_data)) {
  print("Data=$row");
}
mysql_close($link);
?>
I belive that mysql support should be compiled as standard in my version of PHP and I have not done any changes to PHP.INI

Please help, I'm lost?? :?:

Posted: Sat Jan 04, 2003 11:18 am
by aybra
Try this instead

Code: Select all

<?php
$db_user = 'user';
	$db_pass = 'passw';
	$connection = mysql_connect('localhost', $db_user, $db_pass) or die(mysql_error());
	mysql_select_db('my_database', $connection) or die(mysql_error());


//also this
$query = "SELECT * FROM mytab";

?>
all caps in the query section, MySQL is kinda anal bout its command lines that way

Posted: Sat Jan 04, 2003 12:08 pm
by bawen
Thanks for your tips but I still get

Fatal error: Call to undefined function: mysql_connect() in .../s.php on line 4

Which for me indicate that I can't access MYSQL at all from PHP -> undefined function ??

Any idea? :?:

mysql_connect() problem

Posted: Sun Jan 05, 2003 2:42 pm
by bawen
Here comes more data. As I judged, I don't seem to have support in my PHP for MYSQL when I checked the configurations. My PHP seems to be built with

'--with-mysql=shared,/usr'

acording to phpinfo()

What does this mean :?: Does it explain my problem :?:

-------------------------------
My stripped code

Code: Select all

<?php
$link = mysql_connect("localhost", "my_user", "my_passw") or die("Could not connect");
print ("Connected successfully"); 
mysql_close($link); 
?>
and the result
Fatal error: Call to undefined function: mysql_connect() in /var/www/krakestan/db1.php on line 2

Posted: Mon Jan 06, 2003 10:38 am
by PingLeeQuan
forgive me for asking these simple questions... but ...
check to see of teh database is on the same machine
check if you have permission ot connect to teh DB
check to see if you can retrieve any records from any table by using the MYSQLGUI (if you have it)

Try to connect using admin as a username and the PWD for the admin...

check to see if mysql deamon is runing (mysql --status-all)

or through the htt services.

hope this helped and i hope i did not confuse teh matter.

good luck
--quan

RH8 problem

Posted: Mon Jan 06, 2003 12:03 pm
by bawen
I have now sorted out that this is a RH8 problem.

PHP does not come built with MYSQL default support in RH8 packages even thou I thought so. I am not ready yet but will come back with the solution as soon as I am done.

:P