Unix Technical Forum

Can't Connect to server

This is a discussion on Can't Connect to server within the MySQL forums, part of the Database Server Software category; --> I copied this php script and filled in the required info and now I'm getting these error messages: Warning: ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:32 AM
don
 
Posts: n/a
Default Can't Connect to server

I copied this php script and filled in the required info and now I'm getting
these error messages:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local
MySQL server through socket '/tmp/mysql.sock' (2) in
/data/xx/x/xx/xxx/xxxxxx/user/xxxxxx/htdocs/db_upload/txtImport.php on line
9

Warning: mysql_db_query() [function.mysql-db-query]: Can't connect to local
MySQL server through socket '/tmp/mysql.sock' (2) in
/data/xx/x/xx/xxx/xxxxxx/user/xxxxxx/htdocs/db_upload/txtImport.php on line
12

Warning: mysql_db_query() [function.mysql-db-query]: A link to the server
could not be established in
/data/xx/x/xx/xxx/xxxxxx/user/xxxxxx/htdocs/db_upload/txtImport.php on line
12
Invalid DELETE query


<script language="php">

# MySQL database User ID, Password and DB name
$sql_id = "xxxusername for database";
$sql_pwd = "xxxpassword";
$sql_db = "xxxnameof database";

# Connect to the database
mysql_connect('','$sql_id','$sql_pwd');

# Delete the current content of the table
$result = mysql_db_query('$sql_id',"DELETE FROM pet") or die ("Invalid
DELETE query");

# Optimize the current table (recover empty space)
$result = mysql_db_query('$sql_id',"OPTIMIZE TABLE pet") or die ("Invalid
OPTIMIZE query");

# Load local comma separated, fields enclosed by quotes text database - File
has to be in the same directory of this file
$result = mysql_db_query('$sql_id',"LOAD DATA LOCAL INFILE 'pet.txt' INTO
TABLE pet");

# Get how many records are present in the table now
$result = mysql_db_query('$sql_id',"SELECT * from pet") or die ("Invalid
SELECT query");
$rows_count = mysql_num_rows($result);

echo "Records: $rows_count"; mysql_free_result($result);

</script>


What would be the most common mistake/cause for this type of error - this is
my first time loading a table this way.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:32 AM
don
 
Posts: n/a
Default Re: Can't Connect to server

ok no more error messages, But the table is not filling up with the data;
here is the text file and part of the script.......

'Fluffy', 'Harold', 'cat', 'f', '1993-02-04', '\N'
'Claws', 'Gwen', 'cat', 'm', '1994-03-17', '\N'
'Buffy', 'Harold', 'dog', 'f', '1989-05-13','\N'
'Fang', 'Benny', 'dog', 'm', '1990-08-27', '\N'
'Bowser', 'Diane', 'dog', 'm', '1979-08-31','1995-07-29'
'Chirpy', 'Gwen', 'bird', 'f', '1998-09-11', '\N'
'Whistler', 'Gwen', 'bird', '\N', '1997-12-09', '\N'
'Slim', 'Benny', 'snake', 'm', '1996-04-29', '\N'


# Delete the current content of the table
$result = mysql_db_query('$sql_id',"DELETE FROM pet") or die ("Invalid
DELETE query");

# Optimize the current table (recover empty space)
$result = mysql_db_query('$sql_id',"OPTIMIZE TABLE pet") or die ("Invalid
OPTIMIZE query");

# Load local comma separated, fields enclosed by quotes text database - File
has to be in the same directory of this file
$result = mysql_db_query('$sql_id',"LOAD DATA LOCAL INFILE 'pet.txt' INTO
TABLE pet");

# Get how many records are present in the table now
$result = mysql_db_query('$sql_id',"SELECT * from pet") or die ("Invalid
SELECT query");
$rows_count = mysql_num_rows($result);

echo "Records: $rows_count"; mysql_free_result($result);

</script>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:32 AM
Bruce Lortz
 
Posts: n/a
Default Re: Can't Connect to server

This really looks like a php problem rather than a MySQL issue. Can you
connect to the database through alternate means to check the table's number
of rows? I noticed you had no error checking for the "load data infile"
section of the script. User rights to the text file are an often sited
issue with data being loaded via text files. Personally, my server choked
on the comma delimited files, and defaulted with tab delimited.

Provided your copying the text file to the database in the correct manner,
then I think the issue is with the echo statement at the end of the script,
where the double quotes are including the variable. The variable should be
placed outside of the double quotes with the correct concatenator between
them (in the example below, the "period" before $rows_count).

It is all a little confusing to me (being new at mysql and php myself).
This is what I have for a MySQL 5.0.37 database running on Linux Kernel
2.6.21, with Apache 2.2.4, and PHP 5.2.3 (you may want to post your server
parameters as well). I'm assuming your webserver and database are running
off of the same box (assuming the file was loaded correctly):

//open the connection
$conn_pet = mysql_connect("localhost", "xxxusername for database",
"xxxpassword");
//Pick the database to use
mysql_select_db("xxxnameof database",$conn_pet);
//create the SQL statement
$sql = "SELECT * FROM pet";
// execute the SQL statement
$result = mysql_query($sql, $conn_pet) or die(mysql_error());
// check if there is a match
$numresults=mysql_query($sql);
$rows_count=mysql_num_rows($numresults);
echo "Records: " .$rows_count;

I hope this helps,
Lortz


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:32 AM
Captain Paralytic
 
Posts: n/a
Default Re: Can't Connect to server

On 29 Jan, 10:39, "Bruce Lortz" <bruce.lo...@clscenter.com> wrote:
> I think the issue is with the echo statement at the end of the script,
> where the double quotes are including the variable. The variable should be
> placed outside of the double quotes with the correct concatenator between
> them (in the example below, the "period" before $rows_count).


This is rubbish. Before offering advice like this it is best to know
what you are talking about!
Ses:
http://uk3.php.net/manual/en/languag...ring.pa rsing
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:32 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Can't Connect to server

don wrote:
> ok no more error messages, But the table is not filling up with the data;
> here is the text file and part of the script.......
>
> 'Fluffy', 'Harold', 'cat', 'f', '1993-02-04', '\N'
> 'Claws', 'Gwen', 'cat', 'm', '1994-03-17', '\N'
> 'Buffy', 'Harold', 'dog', 'f', '1989-05-13','\N'
> 'Fang', 'Benny', 'dog', 'm', '1990-08-27', '\N'
> 'Bowser', 'Diane', 'dog', 'm', '1979-08-31','1995-07-29'
> 'Chirpy', 'Gwen', 'bird', 'f', '1998-09-11', '\N'
> 'Whistler', 'Gwen', 'bird', '\N', '1997-12-09', '\N'
> 'Slim', 'Benny', 'snake', 'm', '1996-04-29', '\N'
>
>
> # Delete the current content of the table
> $result = mysql_db_query('$sql_id',"DELETE FROM pet") or die ("Invalid
> DELETE query");
>
> # Optimize the current table (recover empty space)
> $result = mysql_db_query('$sql_id',"OPTIMIZE TABLE pet") or die ("Invalid
> OPTIMIZE query");
>
> # Load local comma separated, fields enclosed by quotes text database - File
> has to be in the same directory of this file
> $result = mysql_db_query('$sql_id',"LOAD DATA LOCAL INFILE 'pet.txt' INTO
> TABLE pet");
>
> # Get how many records are present in the table now
> $result = mysql_db_query('$sql_id',"SELECT * from pet") or die ("Invalid
> SELECT query");
> $rows_count = mysql_num_rows($result);
>
> echo "Records: $rows_count"; mysql_free_result($result);
>
> </script>
>
>
>


Don,

Check the results your mysql call to load the data. What error message
do you get?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:32 AM
Bruce Lortz
 
Posts: n/a
Default Re: Can't Connect to server

Sorry Mr. Lautman,

I appreciate the link and have already used it to increase my (very limited)
knowledge of php. I'll try to keep my enthusiasm down to stupid questions,
rather than stupid answers.

Thank you for your input,
Lortz

"Captain Paralytic" <paul_lautman@yahoo.com> wrote in message
news:08596a28-50d4-4946-bf6c-e1aab26ca9e8@j20g2000hsi.googlegroups.com...
> On 29 Jan, 10:39, "Bruce Lortz" <bruce.lo...@clscenter.com> wrote:
>> I think the issue is with the echo statement at the end of the script,
>> where the double quotes are including the variable. The variable should
>> be
>> placed outside of the double quotes with the correct concatenator between
>> them (in the example below, the "period" before $rows_count).

>
> This is rubbish. Before offering advice like this it is best to know
> what you are talking about!
> Ses:
> http://uk3.php.net/manual/en/languag...ring.pa rsing



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 11:32 AM
don
 
Posts: n/a
Default Re: Can't Connect to server

Bruce thanks for trying - my knowledge is little also - thats why I post
:-)


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:49 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com