473,786 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

apache hang when executing PHP code

4 New Member
i am currently using
WindowsXP SP2 all updated
apache 2.2.4
PHP 5.2.3
MySQL 5.0

and apache hang up when running this code

// ------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1.     function query($query="show tables")
  2.     {
  3.         if(!($this->result = mysql_query($query, $this->link)))
  4.         {
  5.             echo "Query to database failure!";
  6.             echo mysql_errno($this->link)." : ".mysql_error($this->link)."\n";
  7.             exit("mysql query error");
  8.         }
  9.         $this->sql = $query;
  10.  
  11.         // also keep track the no. of rows after each query
  12.         $firstWord = explode(" ", $query);
  13.         switch(strtolower($firstWord[0]))
  14.         {
  15.             case 'select':
  16.             {
  17.                 $this->numOfRow = mysql_num_rows($this->result);
  18.                 break;
  19.             }
  20.             case 'insert':
  21.             case 'update':
  22.             case 'delete':
  23.             {
  24.                 $this->numOfRow = mysql_affected_rows($this->link);
  25.                 break;
  26.             }
  27.             default:
  28.             {
  29.                 $this->numOfRow = null;
  30.             }
  31.         }
  32.         return $this->result;
  33.     }
  34.  
it hang when i am executing a query $obj->query() with SQL:
"INSERT INTO `" . $GLOBALS['ygtables']. "` (`app_id`) VALUES ('".$new_app_id ."')" ;
which i have echo the SQL and it seems find.

Do anyone know what happened??

Thanks all for reading.
Jul 26 '07 #1
7 2841
kovik
1,044 Recognized Expert Top Contributor
What do you mean by it hangs? How far into the function does it get?

And, so you know, you may want to reorganize your class. I'd direct you to a long, informative post we had at DevNetwork on writing database classes, but I can't seem to find the link.

EDIT: Found it.
All of us pitched in to help him understand exactly how the database class should work.
Jul 26 '07 #2
pbmods
5,821 Recognized Expert Expert
Heya, wingsss. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Jul 26 '07 #3
wingsss
4 New Member
[PHP]
<?php

/*************** *************** *
Database Querying Class
*************** *************** **/

define('TEST',0 );
define('STUDENT _PROFILE',1);
define('CICO',2 );
//define('STUDENT _PROFILE_100',3 );
define('VPOPMAI L',4);
define('ADMIN_A T_STUDENT',5);
define('CMS',6) ;
define('ADMIN_A T_STAFF',7);
define('USER_AT _STAFF',8);
define('USER_AT _STUDENT',9);
define('USER_AT _VPOPMAIL',10);
define('ADMIN_A T_VPOPMAIL',11) ;
define('ADMIN_A T_AMR',13);
define('USER_AT _AMR',14);
define('AMR_TES T_USER',16);

class MrDB
{
private $host;
private $db;
private $user;
private $pass;
private $link;
public $sql; // the last sql
public $result; // this result set hold the latest retrieved result
public $row; // holding the last row fetched
public $numOfRow; // number of rows in the result set (false on fail, or number of affected rows)
public $rsArray; // convert result set to array for processing
public $mydate; //check date

public function getLink()
{
return $this->link;
}
// ------------------------------------------------------------------------------
public function __construct($db Num=0, $newLink=false)
{
// use absolute path so that the script can be run in console
//include_once($_ SERVER['DOCUMENT_ROOT'].'/../htsecret/dbCfg.inc.php') ;
//include('/var/www/htsecret/dbCfg.inc.php') ;

$this->host = 'localhost';
$this->db = 'prosearch';
$this->user = 'root';
$this->pass = 'hkic';

if(!($this->link = mysql_connect($ this->host, $this->user, $this->pass, $newLink)))
{
echo "Connect to server failure!";
echo mysql_errno($th is->link)." : ".mysql_error($ this->link)."\n";
exit("mysql connection error");
}
if(!mysql_selec t_db($this->db, $this->link))
{
echo "Connect to database failure!";
echo mysql_errno($th is->link)." : ".mysql_error($ this->link)."\n";
exit("mysql select DB error");
}

mysql_query('SE T CHARACTER SET big5', $this->link);
// or die('Query1 failed: '.mysql_error() )

// Replaced by PHP5 destructor
//register_shutdo wn_function(arr ay(&$this, 'close'));
}

// ------------------------------------------------------------------------------
public function __destruct()
{
@mysql_free_res ult($this->result);
mysql_close($th is->link);
}

// ------------------------------------------------------------------------------
public function query($query="s how tables")
{
if(!($this->result = mysql_query($qu ery, $this->link)))
{
echo "Query to database failure!";
echo mysql_errno($th is->link)." : ".mysql_error($ this->link)."\n";
exit("mysql query error");
}
$this->sql = $query;

// also keep track the no. of rows after each query
$firstWord = explode(" ", $query);
switch(strtolow er($firstWord[0]))
{
case 'select':
{
// mysql_num_rows returns false on fail
$this->numOfRow = mysql_num_rows( $this->result);
break;
}
case 'insert':
case 'update':
case 'delete':
{
// mysql_affected_ rows return -1 on fail
$affected = mysql_affected_ rows($this->link);
$this->numOfRow = ($affected == -1) ? false : $affected;
break;
}
default:
{
$this->numOfRow = null;
}
}
return $this->result;
}

// ------------------------------------------------------------------------------
// Escape variable of sql to make safe
public function escapeSql($valu e)
{
// Stripslashes
if(get_magic_qu otes_gpc())
$value = stripslashes($v alue);

return mysql_real_esca pe_string($valu e);
}

// ------------------------------------------------------------------------------
// Strip slashes recursively from value which can be an array
public function stripRecur($val ue)
{
// this function would cause error when strip some chinese characters e.g. ³\
/*
if(is_array($va lue))
$value = array_map(array ('MrDB','stripR ecur'), $value);
elseif(!empty($ value) && is_string($valu e))
$value = stripslashes($v alue);
*/
return $value;
}

// ------------------------------------------------------------------------------
// $table - target table name
// $row - an array of fields and values e.g. array('id'=>10, 'name'=>'Peter' )
public function insert($table, $row)
{
// build the fore part
$fore = "insert into `$table` set ";
// build the rare part
foreach($row as $f => $v)
{
$v = $this->escapeSql($v );
$temp[] = "`$f` = '$v'";
}
$rare = implode($temp,' , ');
$sql = "$fore $rare";
$this->query($sql);

return $this->numOfRow;
}

// ------------------------------------------------------------------------------
// Similar to the method "insert" with additional $keys to specify which element of $row is used as unqiue keys
// e.g. $keys = array('id') or $keys = array('id1','id 2')
public function update($table, $row, $keys)
{
// build the fore part
$fore = "update `$table` set ";

// build the remaining part
foreach($row as $f => $v)
{
$v = $this->escapeSql($v );
if(in_array($f, $keys))
$temp2[] = "`$f` = '$v'";
else
$temp1[] = "`$f` = '$v'";
}

$middle = implode($temp1, ', ');
$rare = implode($temp2, ' and ');

$sql = "$fore $middle where $rare";
$this->query($sql);

return $this->numOfRow;
}

// ------------------------------------------------------------------------------
public function resultToArray($ type='assoc')
{
// go to row 0
mysql_data_seek ($this->result, 0);
// destory the array first
unset($this->rsArray);

switch(strtolow er($type))
{
case 'assoc':
{
while($tempRow= mysql_fetch_ass oc($this->result))
$this->rsArray[] = $this->stripRecur($te mpRow);
break;
}
case 'row':
{
while($tempRow= mysql_fetch_row ($this->result))
$this->rsArray[] = $this->stripRecur($te mpRow);
break;
}
case 'array':
default:
{
while($tempRow= mysql_fetch_arr ay($this->result))
$this->rsArray[] = $this->stripRecur($te mpRow);
break;
}
}
// go back to row 0 before return
mysql_data_seek ($this->result, 0);
return $this->rsArray;
}

// ------------------------------------------------------------------------------
// These 3 functions are just wrapper functions for more OO implementation

public function fetchRow($key=f alse)
{
$tempRow = mysql_fetch_row ($this->result);
$this->row = $this->stripRecur($te mpRow);
return (($key===false) ?($this->row):($this->row[$key]));
}

public function fetchAssoc($key =false)
{
$tempRow = mysql_fetch_ass oc($this->result);
$this->row = $this->stripRecur($te mpRow);
return (($key===false) ?($this->row):($this->row[$key]));
}

public function fetchArray($key =false)
{
$tempRow = mysql_fetch_arr ay($this->result);
$this->row = $this->stripRecur($te mpRow);
return (($key===false) ?($this->row):($this->row[$key]));
}

//-----------------------------------------------------------------------------------------------------------------------------------------------
//-- check valid date value

public function checkData($myda te)
{
list($yy,$mm,$d d)=explode("-",$mydate);
if (is_numeric($yy ) && is_numeric($mm) && is_numeric($dd) )
{
return checkdate($mm,$ dd,$yy);
}
return false;
}
}
?>
[/PHP]


This is the Whole Class that i hv used
And i do the following code in below


[PHP]
$new_app = array();
foreach($_POST as $var=>$value)
{
$new_app[$var]=$value;
}

$new_app_id=sav e_new_app($new_ app);
//$new_app_id=0;
$new_app['app_id']=$new_app_id;
$_SESSION['app_id']=$new_app_id;

[/PHP]

with the function in here
[PHP]


function save_new_app($n ew_app)
{
$db = new MrDB();

$new_app_id=get _new_app_id();
$sql="INSERT INTO `" . $GLOBALS['ygtables']. "` (`app_id`) VALUES ('".$new_app_id ."')" ;
//echo $sql;
$db->query($sql);
//echo "GOT $new_app_id";
foreach($new_ap p as $var=>$value)
{
$sql="UPDATE `" . $GLOBALS['ygtables']. "` SET `".$var."`='".$ value."' where `app_id`='".$ne w_app_id."'";

$db->query($sql);
}

return $new_app_id;
}


[/PHP]

I do the $db->query before this one and it is completely OK.
the problem is when i run this code, the firefox say "waiting for localhost"
and then a long time of waiting and the dead of apache...


What do you mean by it hangs? How far into the function does it get?

And, so you know, you may want to reorganize your class. I'd direct you to a long, informative post we had at DevNetwork on writing database classes, but I can't seem to find the link.

EDIT: Found it.
All of us pitched in to help him understand exactly how the database class should work.
Jul 27 '07 #4
wingsss
4 New Member
sory i am new in here
i ll read the guidline

thx

Heya, wingsss. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Jul 27 '07 #5
pbmods
5,821 Recognized Expert Expert
Heya, Wingsss.

Have you turned on debugging messages?

Sounds like you might be hitting an infinite loop somewhere.

Try adding the following code after the start of each function:
Expand|Select|Wrap|Line Numbers
  1. public function doSomething($param1, $param2)
  2. {
  3.     // [DBuG]
  4.     print("doSomething($param1, $param2)<br />");
  5.     ob_flush();
  6. }
  7.  
This will print the current function, as well as its arguments, which will help you figure out where the problem is.
Jul 27 '07 #6
wingsss
4 New Member
Thanks man
the problem is solved if i put the code on a LAMPP machine, i think the problem might be on windows/apache bug maybe

Heya, Wingsss.

Have you turned on debugging messages?

Sounds like you might be hitting an infinite loop somewhere.

Try adding the following code after the start of each function:
Expand|Select|Wrap|Line Numbers
  1. public function doSomething($param1, $param2)
  2. {
  3.     // [DBuG]
  4.     print("doSomething($param1, $param2)<br />");
  5.     ob_flush();
  6. }
  7.  
This will print the current function, as well as its arguments, which will help you figure out where the problem is.
Jul 31 '07 #7
pbmods
5,821 Recognized Expert Expert
Heya, wingsss.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 31 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2487
by: Ole Kramer, SFS GmbH | last post by:
We have installed PHP 5.0.1 on a Windows 2003 Server with IIS6 in ISAPI mode. The processing of .php files works fine with our basis version of the php.ini file. But, as soon as we edit the php.ini file to outcomment the line "extension=php_sybase_ct.dll" (or "extension=php_pdf.dll") and restart the IIS6, the web site is not able to work with .php files properly, instead the web server seems to hang with any .php file. Does anybody have...
0
1712
by: Bill | last post by:
I've recently built a new server on which I've tried to configure and install PHP5 (I've now tried 5.0.4, 5.0.5, and 5.1.0RC1) along with Apache 1.3.33 and net-snmp 5.2.1.2. (Building PHP5 as an Apache module) Everything compiles just fine, but when I try to call any of the SNMP functions (i.e. snmpget) from a PHP script on a web page, I get the following error: Warning: snmpget() : Could not open snmp connection: Unknown host in...
3
2613
by: Ember | last post by:
Doozie of a problem here - may open a ticket with support, but wanted to see what others had to say first... We have an AIX 5.2 server with DB2 V8 FP5 and 32-bit instance. ~45GB db. Reorgs and runstats are done weekly and the server is at least decently tuned, although we're bumping up against the memory limits with 32-bit. There is a series of 16 queries run in varying orders by the users referred to as "mega-measures". Normally these...
0
1733
by: szehau | last post by:
Hi all, I have a program written in C with embeded SQL. Following are the configuration: DB2/LINUX 8.1.5 Thread model: posix gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7) My problems are as following
4
6207
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor. Each task is processed in a separate thread. Each of the executer threads is an STA thread, and it goes ahead and executes the task. No problems are encountered when tasks are executed one at a time, but when multiple tasks are executed...
5
3120
by: m.banaouas | last post by:
Hi, bonjour, witch versions are suitable to use for apache & mod_python ? Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent versions) without facing any known major issue ? thanks for any help.
2
2537
by: comp.lang.php | last post by:
I have an app that is going berzerk on its own; without any code or environmental changes of any kind, for some bizarre reason it will randomly just hang, spawn multiple Apache processes and completely ignore max_execution_time, literally running infinitely. Using PHP 5.2.0, Apache 1.3 and Win XP Is this normal "bizarre" behavior that can occur within this setup; if so, what workarounds have you found to combat this, other than the...
3
2304
by: Raja | last post by:
Hi, I am trying to write a cgi program which would be executed on browser with Apache server installed. The program would make a connection to a database using cx_Oracle module and display results on page. The code is working fine on the command line but when executing it on the browser i get the famouse "Premature end of script headers" error.
1
3396
by: reptoid | last post by:
Hi there, I know this question has been probably asked before, but all the answers I found couldn't help me. I am a noob when it comes to Linux, so please bear with me. I am running Suse Enterprise Server 10 and I installed Apache 2 and PHP 5 according to the installation guidelines, and I created the common test.php file. The Problem is I keep getting this error (from apache errorlog): (13) Permission denied: file permissions deny server...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.