simple problem :|

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kanec
Forum Newbie
Posts: 7
Joined: Thu Jun 28, 2007 4:13 am

simple problem :|

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
?>
kanec
Forum Newbie
Posts: 7
Joined: Thu Jun 28, 2007 4:13 am

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply