Hi! I'm writing a class layer between mysql and my application... at first, its working perfectly untill i added the method db_fetch_result($result) and db_fetch_result()... I looked at the the http error log at /var/log/httpd/error_log and what i found out is that... my script is causing mod_php to signal a Segmentation Fault. 🙁
Here is the code:
<?php
/*
Error Reporting COnfig:
*/
error_reporting(E_ALL); / debug mode; all error /
error_reporting(E_ERROR); / production mode: /
/ abstract class /
class ocms_connection {
var $db_name;
var $db_host;
var $db_user;
var $db_password;
var $db_con_id;
var $db_error_no;
var $db_error_msg;
var $error_msg;
var $last_result;
function ocms_connection($db_host, $db_name, $db_user, $db_password) {
$this->db_name = $db_name;
$this->db_host = $db_host;
$this->db_user = $db_user;
$this->db_password = $db_password;
} //end.ocms_connection constructor
function open() {
$this->db_con_id = mysql_connect($this->db_host, $this->db_user, $this->db_password);
$this->db_error_no = mysql_errno($this->db_con_id);
$this->db_error_msg = mysql_error($this->db_con_id);
if ($this->db_con_id) {
if (!mysql_select_db($this->db_name,$this->db_con_id)) {
$this->db_error_no = mysql_errno($this->db_con_id);
$this->db_error_msg = mysql_error($this->db_con_id);
$this->close();
return FALSE;
}
}
return $this->db_con_id;
} //open a connection
function close() {
mysql_close($this->db_con_id);
} //close a connection
function get_connection() {
return $this->db_con_id;
}
function db_query($sql_query) {
$result = mysql_query(mysql_escape_string($sql_query),$this->db_con_id);
echo mysql_escape_string($sql_query);
$this->last_result = $result;
if (!$result) {
$this->db_error_no = mysql_errno($this->db_con_id);
$this->db_error_msg = mysql_error($this->db_con_id);
return FALSE;
}
return $result;
}
function db_fetch_result($result) {
if (!is_resource($result)) {
$this->db_error_msg = "$result is not a valid resource";
return FALSE;
}
$row = mysql_fetch_assoc($result);
echo $row;
if (!$row) {
$this->db_error_msg = "No more rows.";
}
return $row;
}
function db_fetch_result() {
if (!is_resource($this->last_result)) {
$this->db_error_msg = $this->last_result . " is not a valid resource";
return FALSE;
}
while ($row = $this->db_fetch_result($this->last_result)) {
echo "fetching..";
$rows[] = $rows;
}
return $rows;
}
} //end.ocms_connection
$con = new ocms_connection("localhost","openOCMS","openocms","openocms");
if (!$con->open()) {
echo $con->db_error_no . " " . $con->db_error_msg;
} else {
$result = $con->db_query("select * from terms");
$rows = $con->db_fetch_result($result);
for ($x=0; $x < count($rows); $x++) {
echo $rows[$x]["term_id"] . " " . $rows[$x]["term_description"] . " " . $rows[$x]["term_short_desc"] . "<br>\n";
}
$con->close();
}
echo "end.";
?>
I hope you guys can help me out with this trouble... thank you!! I'm creating an Online Class Management System (E-Learning Style)... as a hobby..
Thank you.. jun