Page 1 of 1

simple problem :|

Posted: Thu Jun 28, 2007 4:20 am
by kanec
i've done this before but now it doesn't work, so i'm puzzled why..
i'm using:
-mysql server 5.0.41 on localhost:3306
-php 5.2.3
-apache 2.2 on localhost:12380

Code: Select all

<?php
error_reporting(E_ALL); 

$con = mysql_connect('localhost','root','passwd') or die(mysql_error()); 
mysql_select_db('twvr') or die(mysql_error()); 

$lines = gzfile('file.txt.gz');
if(!is_array($lines)) die("File could not be opened"); 
foreach($lines as $line) {
	
	list($id, $name,$stuff) = explode(',', $line);
	$name = urldecode($name);

	$name = addslashes($name);
	mysql_query("INSERT INTO village(ID,name,stuff) VALUES('$id','$name','$stuff')",$con);	
}

mysql_close($con);

?>
i've tried debugged PHP code, but i do not know how ;o
and mysqld-debug gives me nothing - so i presume i'm getting no connection to mysqld?
it seems to stop at "
$con = mysql_connect('localhost','root','passwd') or die(mysql_error()); "
but i get NO error whatsoever, so i don't know where to begin :S

Posted: Thu Jun 28, 2007 4:29 am
by volka
please try

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

echo '<div>Debug: mysql_connect</div>';
$con = mysql_connect('localhost','root','passwd') or die(mysql_error());
echo '<div>Debug: mysql_select_db</div>';
mysql_select_db('twvr') or die(mysql_error());

echo '<div>Debug: gzfile</div>';
$lines = gzfile('file.txt.gz');
if(!is_array($lines)) die("File could not be opened");
foreach($lines as $line) {
       
        list($id, $name,$stuff) = explode(',', $line);
        $name = urldecode($name);

        $name = addslashes($name);
        mysql_query("INSERT INTO village(ID,name,stuff) VALUES('$id','$name','$stuff')",$con); 
}

mysql_close($con);
?>

Posted: Thu Jun 28, 2007 5:31 am
by kanec
oh lol, i didn't have php-mysql support in apache.
thank you

now i'm wondering if is there a way to optimize this code?

Code: Select all

foreach($lines as $line) {
       
        list($id, $name,$stuff) = explode(',', $line);
        $name = urldecode($name);

        $name = addslashes($name);
        mysql_query("INSERT INTO village(ID,name,stuff) VALUES('$id','$name','$stuff')",$con);
}
if not that.. is there a way to set the "max_execution_time" var specifically for this one script?

Posted: Thu Jun 28, 2007 5:40 am
by volka
You could use the mysqli extension and a prepared statement.
You're probably also interested in http://de2.php.net/set_time_limit

Posted: Thu Jun 28, 2007 10:47 am
by pickle
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.