...

View Full Version : php "connections" mysql database problem



Martinj
12-24-2006, 11:41 PM
Hello folks..my first post here and im in a bit of a quandry with php and connecting to mysql.. heres the basis of the problem.. My host wont let me access MySQL directly from dreamweaver so i have MySQL set up on localhost with phpmyadmin to connect...
heres my problem my site is in php as some of it is dynamic and i need to collect registratio info for a members database, when i've built the necessary pages and database on localhost he thing runs as good as i want it to with no problems, registration is not a problem, information of the registrant is collected and left in the relevant table in MySQL (on localhost of course)
now heres where it all goes wrong..i upload everything to my hosts server. same database details are held on that MySQL server,yet it always fails at this point


Warning: mysql_pconnect() [function.mysql-pconnect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /websites/LinuxPackage02/uk/_k/is/uk-kiss.com/public_html/Connections/ukkiss.php on line 9

Fatal error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /websites/LinuxPackage02/uk/_k/is/uk-kiss.com/public_html/Connections/ukkiss.php on line 9

would i be right in saying that my localhost must have the same username/password etc as my hosted MySQL so that my connections folder (well the file thats in there) can connect to my hosted Mysql database or could i just edit the file in connections folder?..or as i fear is there lots more to this..thanks for your time..

Crimsonjade
12-24-2006, 11:47 PM
Can you post your connection line so we can see it?

I know some places have both MySQL4 and MySQL5. In order to connect to MySQL5 you have to do something like:


/* Connecting, selecting database */
$link = mysql_connect("localhost:/tmp/mysql5.sock", "user", "pass")


Notice the part after localhost? Check with your host provider to see how they want you to connect to the database.

Martinj
12-25-2006, 12:10 AM
@ crimsonjade thanks for the quick reply, Im a total newbie at this so im kinda wondering what you mean by conections string, how would i get to find that out?

Crimsonjade
12-25-2006, 12:46 AM
By "connection line" I meant the line of code that shows us how you are connecting to your MySQL database from within your script.

For example:


$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$result = mysql_query('SELECT name FROM work.employee');
if (!$result) {
die('Could not query:' . mysql_error());
}

mysql_close($link);


Before I submit a query, I need to specify which database I am connecting to. If you do not have a line with the mysql_connect() function in it, you are probably not connecting to the database.

If you do not know where to add the mysql_connect() line, post your script here so we can see it and help you out. If you do post your script, make sure to hide any sensitive information (e.g. the username/password to your database).

SELF_TAUGHT
12-25-2006, 03:57 AM
I may be missing the point here and if so please forgive me. I use a config.php file for the sql connection strings. I two have a localhost and a hosted mysql and web server. I make the scripts on my localhost and then upload them to the server. Instead of putting the username and password and host in the file itself I just use something like this. All the mysql connection and database selection strings are kept in the config.php file.



include 'config.php';
$result = mysql_query('SELECT name FROM work.employee');
if (!$result) {
die('Could not query:' . mysql_error());
}

mysql_close($link);


This way, when I upload the file the mysql info changes without me doing any of the editing.

Also, can you connect at all? Because most hosted mysql database will (even though you register with say scriptin as the mysql username your username will actually be scriptinghelp_scriptin and if you create the hosted database as employee the database conection will have to actually be scriptinghelp_employee.)

Who is hosting your Mysql Database. That will also help us out.

Martinj
12-26-2006, 10:48 AM
sorry for the delay in replying,xmas festivities etc!..

Well herein lies a problem with config.php i cant seem to find one the only config. files that i have are config.inc and config.default...
the site im building contains just 3 pages index.php,register.php (this is the page im having problems with) and a thankyou.php which the user returns to after entering there details on the register page,, the error im getting is


Warning: mysql_pconnect() [function.mysql-pconnect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /websites/LinuxPackage02/uk/_k/is/uk-kiss.com/public_html/Connections/ukkiss.php on line 9

Fatal error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /websites/LinuxPackage02/uk/_k/is/uk-kiss.com/public_html/Connections/ukkiss.php on line 9

and here is the first line of code on "register.php" page


<?php require_once('Connections/ukkiss.php'); ?>
<?php

below is the file it points too with the error on line 9


<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_ukkiss = "localhost";
$database_ukkiss = "********";
$username_ukkiss = "********";
$password_ukkiss = "********";
$ukkiss = mysql_pconnect($hostname_ukkiss, $username_ukkiss, $password_ukkiss) or trigger_error(mysql_error(),E_USER_ERROR);
?>

below is a reply from my host "pipex" which to a newbie like me doesnt exactly clear things up

The file at...

/websites/LinuxPackage02/uk/_k/is/uk-kiss.com/public_html/registration.php

..is referencing a file:

./Connections/ukkiss.php

..which the server looks for at:

/websites/LinuxPackage02/uk/_k/is/uk-kiss.com/Connections/ukkiss.php

..and, because this doesn't exist, it throws an error.

You need to review your code, or find out how to set /websites/LinuxPackage02/uk/_k/is/uk-kiss.com/public_html/ as the document root on the remote server in your publishing software. This should be able to work with just public_html , as that is the web root in relation to your FTP home.

any ideas?..thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum