Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
bawen
Forum Newbie
Posts: 5 Joined: Wed Jan 01, 2003 12:44 pm
Location: Trollhättan, Sweden
Post
by bawen » Sat Jan 04, 2003 10:09 am
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??
aybra
Forum Commoner
Posts: 56 Joined: Sun Nov 24, 2002 12:52 am
Post
by aybra » Sat Jan 04, 2003 11:18 am
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
bawen
Forum Newbie
Posts: 5 Joined: Wed Jan 01, 2003 12:44 pm
Location: Trollhättan, Sweden
Post
by bawen » Sat Jan 04, 2003 12:08 pm
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?
bawen
Forum Newbie
Posts: 5 Joined: Wed Jan 01, 2003 12:44 pm
Location: Trollhättan, Sweden
Post
by bawen » Sun Jan 05, 2003 2:42 pm
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
PingLeeQuan
Forum Commoner
Posts: 58 Joined: Tue Sep 03, 2002 8:08 am
Post
by PingLeeQuan » Mon Jan 06, 2003 10:38 am
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
bawen
Forum Newbie
Posts: 5 Joined: Wed Jan 01, 2003 12:44 pm
Location: Trollhättan, Sweden
Post
by bawen » Mon Jan 06, 2003 12:03 pm
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.