Fedora Linux Support Community & Resources Center
  #1  
Old 7th October 2004, 03:55 PM
Sail@ Offline
Registered User
 
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 31
Posts: 7
MYSQL won't let me connect from PHP script

I've written a small script that connects to a mysql database (localhost) and adds some data into a table.

Now when i execute it i get the following error from the script:
Code:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
I know that the mysql.sock is located at that place in my system and I've also connected from the console, everything works.


Code:
[teddy@pr0nstar mysql]$ mysql -u thai -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17 to server version: 3.23.58-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
I've tried executing the script from the console with "php -f test.php" and everything runs fine, all data gets added into the database.

Maybe it's got something to do with Apache, I don't know what to do...
Reply With Quote
  #2  
Old 7th October 2004, 04:10 PM
ewdi Offline
Retired Admin
 
Join Date: Jan 2004
Location: Penguin Land
Age: 64
Posts: 1,939
can you post your code?
__________________
+ Visit My new blog
- [B]SlashGear US, SlashGear Japan, and
+Founder & Admin of www.fedoraforum.org

Follow me at http://twitter.com/ewdi

Laptop : MacBook Pro 2.4Ghz 4GB DDR, 20-inch iMac Aluminium/4GB RAM
Reply With Quote
  #3  
Old 7th October 2004, 04:38 PM
Sail@ Offline
Registered User
 
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 31
Posts: 7
PHP Code:
<HTML>
<?php
        $namn 
"Mysqltestdata";
        
$medd "OWNAGE!";
        print 
"MYSQL QUERY: <BR>";
        
$myconn mysql_connect('localhost''thai''password')
                or die(
"Could not connect to MYSQL Server.<BR>" mysql_error());
        
mysql_select_db("thailand")
                or die(
"Could not select database.");
        
$laggtill "INSERT INTO test (namn, medd) VALUES ('$namn', '$medd')";
        
mysql_query($laggtill)
                or die(
"Could not add information.");
        
mysql_close($myconn);
        print 
"Still alive?";
?>
</HTML>
This is EXACTLY what the script prints when called from the web http://127.0.0.1/test.php :
Code:
MYSQL QUERY: 
Could not connect to MYSQL Server.
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
When using commandline "php -f test.php" I get this:
Code:
[root@pr0nstar html]# php -f test.php
<HTML>
MYSQL QUERY: <BR>Still alive?</HTML>
Reply With Quote
  #4  
Old 7th October 2004, 05:20 PM
gablaxian Offline
Registered User
 
Join Date: Aug 2004
Location: Planet Irk
Age: 31
Posts: 76
did you build either php, or mysql youself?
Reply With Quote
  #5  
Old 7th October 2004, 05:25 PM
Sail@ Offline
Registered User
 
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 31
Posts: 7
Nope, I used yum to install everything.
Reply With Quote
  #6  
Old 7th October 2004, 05:28 PM
ewdi Offline
Retired Admin
 
Join Date: Jan 2004
Location: Penguin Land
Age: 64
Posts: 1,939
is php-mysql installed? or php-DBD at least
__________________
+ Visit My new blog
- [B]SlashGear US, SlashGear Japan, and
+Founder & Admin of www.fedoraforum.org

Follow me at http://twitter.com/ewdi

Laptop : MacBook Pro 2.4Ghz 4GB DDR, 20-inch iMac Aluminium/4GB RAM
Reply With Quote
  #7  
Old 7th October 2004, 06:11 PM
Sail@ Offline
Registered User
 
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 31
Posts: 7
yep, php-mysql is installed.
the funtion mysql_connect() exists.
I don't have a clue
Reply With Quote
  #8  
Old 8th October 2004, 04:36 AM
triplehead Offline
Registered User
 
Join Date: Mar 2004
Location: Helsinki, Finland
Age: 41
Posts: 187
is mysqld service on
Code:
chkconfig --list mysqld
__________________
Desktop1: Shuttle SN85G4, AMD64 3200+, 1GB 400MHz, EIZO 778, Asus N6600GT
Desktop2: Shuttle SN20G5, AMD64 X2 4200+, 1GB 400MHz, EIZO 778, ATI Radeon Express 200
Server:AMD64 3200+, 1GB 400MHz, matrox g400
network: G.SHDSL 2.3/2.3 Mbit/s
Reply With Quote
  #9  
Old 9th October 2004, 09:38 AM
Sail@ Offline
Registered User
 
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 31
Posts: 7
It's activated only in / for runlevel 3.
That's the way it's supposed to be, right?

I'm gonna remove apache, php and mysql and reinstall them. Maybe it's just a version conflict? Anyway, I'll be back telling you the outcome of all this.
Reply With Quote
  #10  
Old 9th October 2004, 10:51 AM
Sail@ Offline
Registered User
 
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 31
Posts: 7
Okay, I've reinstalled the packages.
Still the same problem :/

Code:
MYSQL QUERY:
Could not connect to MYSQL Server.
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
Reply With Quote
  #11  
Old 9th October 2004, 11:43 PM
ieuuk Offline
Registered User
 
Join Date: Oct 2004
Location: uk
Age: 27
Posts: 705
do you know if it put mysql.sock back to how it was originally?
__________________
ieuuk :D

Registered Linux User: #373024
Reply With Quote
  #12  
Old 10th October 2004, 05:14 PM
Sail@ Offline
Registered User
 
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 31
Posts: 7
Problem solved! (almost :P)

Screw mysql.sock, I now connect through tcp instead
An ugly solution, but I don't have the time / brains to fiddle with this anymore.
Thanks for all the help!
Reply With Quote
  #13  
Old 15th October 2004, 10:41 PM
triplehead Offline
Registered User
 
Join Date: Mar 2004
Location: Helsinki, Finland
Age: 41
Posts: 187
still, what this gives you
Code:
chkconfig --list mysqld
__________________
Desktop1: Shuttle SN85G4, AMD64 3200+, 1GB 400MHz, EIZO 778, Asus N6600GT
Desktop2: Shuttle SN20G5, AMD64 X2 4200+, 1GB 400MHz, EIZO 778, ATI Radeon Express 200
Server:AMD64 3200+, 1GB 400MHz, matrox g400
network: G.SHDSL 2.3/2.3 Mbit/s
Reply With Quote
  #14  
Old 16th October 2004, 01:46 AM
Kalle Offline
Registered User
 
Join Date: Oct 2004
Posts: 2
Hi people!

I used to have the same problem, but the solution was quite obvious . Take a look at this: http://forums.devarticles.com/archive/t-4635


Cheers,

Kalle!
Reply With Quote
Reply

Tags
connect, mysql, php, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
connect to sql server from a script shell pattchen Using Fedora 0 2nd May 2007 10:23 AM
Can't connect to mysql? fvs Using Fedora 2 1st May 2006 10:55 PM
cannot connect to mysql with php script? shams Using Fedora 3 29th April 2006 02:02 AM
When to connect to mysql DB Mat Programming & Packaging 11 7th July 2005 05:47 AM


Current GMT-time: 14:29 (Thursday, 02-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat