 |
 |
 |
 |
| Servers & Networking Discuss any Fedora server problems and Networking issues such as dhcp, IP numbers, wlan, modems, etc. |

7th October 2004, 03:55 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 30
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...
|

7th October 2004, 04:10 PM
|
 |
Retired Admin
|
|
Join Date: Jan 2004
Location: Penguin Land
Age: 63
Posts: 1,939

|
|
|
can you post your code?
|

7th October 2004, 04:38 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 30
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>
|

7th October 2004, 05:20 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Location: Planet Irk
Age: 30
Posts: 76

|
|
|
did you build either php, or mysql youself?
|

7th October 2004, 05:25 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 30
Posts: 7

|
|
|
Nope, I used yum to install everything.
|

7th October 2004, 05:28 PM
|
 |
Retired Admin
|
|
Join Date: Jan 2004
Location: Penguin Land
Age: 63
Posts: 1,939

|
|
|
is php-mysql installed? or php-DBD at least
|

7th October 2004, 06:11 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 30
Posts: 7

|
|
yep, php-mysql is installed.
the funtion mysql_connect() exists.
I don't have a clue
|

8th October 2004, 04:36 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Helsinki, Finland
Age: 40
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
|

9th October 2004, 09:38 AM
|
|
Registered User
|
|
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 30
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.
|

9th October 2004, 10:51 AM
|
|
Registered User
|
|
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 30
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)
|

9th October 2004, 11:43 PM
|
 |
Registered User
|
|
Join Date: Oct 2004
Location: uk
Age: 26
Posts: 705

|
|
|
do you know if it put mysql.sock back to how it was originally?
__________________
ieuuk :D
Registered Linux User: #373024
|

10th October 2004, 05:14 PM
|
|
Registered User
|
|
Join Date: Oct 2004
Location: Gothenburg, Sweden
Age: 30
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!
|

15th October 2004, 10:41 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Location: Helsinki, Finland
Age: 40
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
|

16th October 2004, 01:46 AM
|
|
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!
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 12:43 (Saturday, 18-05-2013)
|
|
 |
 |
 |
 |
|
|