Page 1 of 1

php mysql statement hangs?

Posted: Sun Nov 30, 2008 11:21 pm
by Kroonen
Hi,

I'm trying to put the rfxmeter values into a mysql database with php
He puts it in but the script doesn't come to a prompt, what do I wrong?

#!/usr/bin/php

<?php
$link = mysql_connect('localhost', 'rfxcom', 'rfxcom')or die('Couldnot connect: ' . mysql_error());

mysql_select_db( "rfxcom") or die('Could not select database');

$sql = "SELECT power FROM rfxpower ORDER by time DESC";

$query = mysql_query($sql);

$result = mysql_result($query, 0);

$data = shell_exec('/usr/local/bin/heyu rfxpower l2');

$verbruik = $data - $result;

$query2 = "insert into rfxpower(power,verbruik) values
('$data','$verbruik')";

mysql_query($query2);

// Free resultset
mysql_free_result($query);

// Closing connection
mysql_close($link);

?>

php mysql statement hangs?

Posted: Sun Nov 30, 2008 11:45 pm
by Mdamen
Are you sure it's not hanging on some command?

Try adding some echo statements in between, like this:

Code: Select all

<?php
$link = mysql_connect('localhost', 'rfxcom', 'rfxcom')or die('Couldnot connect: ' . mysql_error());
echo "connected to mysql server";

mysql_select_db( "rfxcom") or die('Could not select database');
echo "database selected";
etc.

If that runs all the way to the last action, which is the mysql_close function in this case. Try adding the following, to make sure the script exits:

Code: Select all

exit();
for more info see: http://www.php.net/exit

Maarten Damen
www.maartendamen.com

php mysql statement hangs?

Posted: Tue Dec 02, 2008 10:02 pm
by Kroonen
I got the problem, de php-cli form debian etch is a bug with exit.

Is it simple to get the script in perl. Any help

kind regards richard