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: ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |
| |||
| 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> |
| |||
| 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 |
| |||
| 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 |
| |||
| 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 ================== |
| |||
| 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 |