本文整理汇总了PHP中sql_query::session_init方法的典型用法代码示例。如果您正苦于以下问题:PHP sql_query::session_init方法的具体用法?PHP sql_query::session_init怎么用?PHP sql_query::session_init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sql_query
的用法示例。
在下文中一共展示了sql_query::session_init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
log_write("error", "sql_query", "Unable to connect to traffic service usage database!");
error_flag_field("SERVICE_TRAFFIC_DB_HOST");
error_flag_field("SERVICE_TRAFFIC_DB_NAME");
error_flag_field("SERVICE_TRAFFIC_DB_USERNAME");
error_flag_field("SERVICE_TRAFFIC_DB_PASSWORD");
} else {
log_write("notification", "sql_query", "Tested successful connection to traffic usage database");
$obj_sql->session_terminate();
}
}
/*
Test CDR Database
*/
if ($data["SERVICE_CDR_DB_TYPE"] == "mysql_cdr_daily") {
$obj_sql = new sql_query();
if (!$obj_sql->session_init("mysql", $data["SERVICE_CDR_DB_HOST"], $data["SERVICE_CDR_DB_NAME"], $data["SERVICE_CDR_DB_USERNAME"], $data["SERVICE_CDR_DB_PASSWORD"])) {
log_write("error", "sql_query", "Unable to connect to CDR service usage database!");
error_flag_field("SERVICE_CDR_DB_HOST");
error_flag_field("SERVICE_CDR_DB_NAME");
error_flag_field("SERVICE_CDR_DB_USERNAME");
error_flag_field("SERVICE_CDR_DB_PASSWORD");
} else {
log_write("notification", "sql_query", "Tested successful connection to CDR usage database");
$obj_sql->session_terminate();
}
}
/*
Process Errors
*/
if (error_check()) {
$_SESSION["error"]["form"]["config_services"] = "failed";
示例2: Pricing
//.........这里部分代码省略.........
Just a simple query here, however if this is a TOLLFREE service, then we need to reverse
the query to charge for inbound calls rather than outbound.
*/
log_write("debug", "service_usage_cdr", "Fetching usage records FOR {$ddi} FROM {$date_start} TO {$date_end}");
$obj_cdr_sql = new sql_query();
if ($this->obj_service->data["typeid_string"] == "phone_tollfree") {
log_write("debug", "service_usage_cdr", "Billing for tollfree service on {$ddi}");
// NOTE! for toll-free services, we reverse src and dst for reverse billing calculations
$obj_cdr_sql->string = "SELECT id, date, price, usage1 as dst, usage2 as src, usage3 as billsec, billgroup FROM service_usage_records WHERE id_service_customer='" . $this->id_service_customer . "' AND date >= '{$date_start}' AND date < '{$date_end}'";
$obj_cdr_sql->execute();
} else {
$obj_cdr_sql->string = "SELECT id, date, price, usage1 as src, usage2 as dst, usage3 as billsec, billgroup FROM service_usage_records WHERE id_service_customer='" . $this->id_service_customer . "' AND date >= '{$date_start}' AND date < '{$date_end}'";
$obj_cdr_sql->execute();
}
/*
Calculate costs of calls
*/
if ($obj_cdr_sql->num_rows()) {
$obj_cdr_sql->fetch_array();
foreach ($obj_cdr_sql->data as $data_cdr) {
// determine price
if ($data_cdr["price"] != "0.00") {
// a price has already been set - make use of that
$charges = array();
$charges["price"] = $data_cdr["price"];
$charges["billgroup"] = $data_cdr["billgroup"];
} else {
$charges = $obj_cdr_rate_table->calculate_charges($data_cdr["billsec"], $data_cdr["src"], $data_cdr["dst"], $this->data_local[$data_cdr["src"]], $this->data_ddi);
// update the charges in the records
$sql_obj = new sql_query();
$sql_obj->string = "UPDATE service_usage_records SET price='" . $charges["price"] . "', billgroup='" . $charges['billgroup'] . "' WHERE id='" . $data_cdr["id"] . "'";
$sql_obj->execute();
}
// add to structure - we use the SRC as the DDI
$this->data[$data_cdr["src"]][$charges["billgroup"]]["charges"] += $charges["price"];
// TODO: this won't catch issues where the DDIs configured don't match the SRC DDI (although it should always!)
}
}
} else {
/*
Connect to External SQL database
*/
// fetch all calls for that DDI from the DB for the selected period
$obj_cdr_db_sql = new sql_query();
if (!$obj_cdr_db_sql->session_init("mysql", $GLOBALS["config"]["SERVICE_CDR_DB_HOST"], $GLOBALS["config"]["SERVICE_CDR_DB_NAME"], $GLOBALS["config"]["SERVICE_CDR_DB_USERNAME"], $GLOBALS["config"]["SERVICE_CDR_DB_PASSWORD"])) {
return 0;
}
/*
We fetch the call records by looping through all the DDIs for this customer, fetching all the records
for those DDIs and then calculating the cost for each call
*/
foreach ($this->data_ddi as $ddi) {
// calculate end date to be the first date of the next period - failure to do so would mean we would
// miss the last day of the billing period in the query;
$date_start = $this->date_start;
$tmp_date = explode("-", $this->date_end);
$date_end = date("Y-m-d", mktime(0, 0, 0, $tmp_date[1], $tmp_date[2] + 1, $tmp_date[0]));
/*
Fetch Data
Just a simple query here, however if this is a TOLLFREE service, then we need to reverse
the query to charge for inbound calls rather than outbound.
*/
log_write("debug", "service_usage_cdr", "Fetching usage records FOR {$ddi} FROM {$date_start} TO {$date_end}");
if ($this->obj_service->data["typeid_string"] == "phone_tollfree") {
log_write("debug", "service_usage_cdr", "Billing for tollfree service on {$ddi}");
// NOTE! for toll-free services, we reverse src and dst for reverse billing calculations
$obj_cdr_db_sql->string = "SELECT calldate, billsec, dst as src, src as dst FROM cdr WHERE disposition='ANSWERED' AND dst='{$ddi}' AND calldate >= '{$date_start}' AND calldate < '{$date_end}'";
$obj_cdr_db_sql->execute();
} else {
$obj_cdr_db_sql->string = "SELECT calldate, billsec, src, dst FROM cdr WHERE disposition='ANSWERED' AND src='{$ddi}' AND calldate >= '{$date_start}' AND calldate < '{$date_end}'";
$obj_cdr_db_sql->execute();
}
/*
Calculate costs of calls
*/
if (!isset($this->data[$ddi][$charges["billgroup"]]["charges"])) {
$this->data[$ddi][$charges["billgroup"]]["charges"] = 0;
}
if ($obj_cdr_db_sql->num_rows()) {
$obj_cdr_db_sql->fetch_array();
foreach ($obj_cdr_db_sql->data as $data_cdr) {
// determine price
$charges = $obj_cdr_rate_table->calculate_charges($data_cdr["billsec"], $data_cdr["src"], $data_cdr["dst"], $this->data_local[$ddi], $this->data_ddi);
// create local usage record for record keeping purposes
$sql_obj = new sql_query();
$sql_obj->string = "INSERT INTO service_usage_records (id_service_customer, date, price, usage1, usage2, usage3, billgroup) VALUES ('" . $this->id_service_customer . "', '" . $data_cdr["calldate"] . "', '" . $charges["price"] . "', '" . $data_cdr["src"] . "', '" . $data_cdr["dst"] . "', '" . $data_cdr["billsec"] . "', '" . $charges["billgroup"] . "')";
$sql_obj->execute();
// add to structure
$this->data[$ddi][$charges["billgroup"]]["charges"] += $charges["price"];
}
}
}
// end of DDI loop
/*
Disconnect from database
*/
$obj_cdr_db_sql->session_terminate();
}
// end of external data source
}
示例3: SUM
function fetch_usage_traffic()
{
log_write("debug", "service_usage_traffic", "Executing fetch_usage_traffic()");
/*
Fetch data traffic types
Note that this doesn't query overrides, since the override options will never impact which traffic types that exist,
only how they are billed by include/services/inc_services_invoicegen.php
*/
$traffic_types = sql_get_singlecol("SELECT traffic_types.type_label as col FROM `traffic_caps` LEFT JOIN traffic_types ON traffic_types.id = traffic_caps.id_traffic_type WHERE traffic_caps.id_service='" . $this->obj_service->id . "'");
/*
Fetch raw usage data from DB
*/
if ($GLOBALS["config"]["SERVICE_TRAFFIC_MODE"] == "internal") {
/*
Internal Database
Use the internal database - this stores the usage information for upload/download mapped against the customer's
IP address.
TODO: Currently all traffic is just assigned against type any/*, this should be upgraded to properly support
the different traffic types.
*/
log_write("debug", "service_usage_traffic", "Fetching traffic records from internal database");
// fetch upload/download stats
$sql_obj = new sql_query();
$sql_obj->string = "SELECT SUM(usage1) as usage1, SUM(usage2) as usage2 FROM service_usage_records WHERE id_service_customer='" . $this->id_service_customer . "' AND date>='" . $this->date_start . "' AND date<='" . $this->date_end . "'";
$sql_obj->execute();
$sql_obj->fetch_array();
$this->data["usage1"] = $sql_obj->data[0]["usage1"];
$this->data["usage2"] = $sql_obj->data[0]["usage2"];
unset($sql_obj);
// create a total of both usage columns
$sql_obj = new sql_query();
$sql_obj->string = "SELECT '" . $this->data["usage1"] . "' + '" . $this->data["usage2"] . "' as totalusage";
$sql_obj->execute();
$sql_obj->fetch_array();
$this->data["total"]["*"] = $sql_obj->data[0]["totalusage"];
$this->data["total"]["total"] = $sql_obj->data[0]["totalusage"];
unset($sql_obj);
// we now have the raw usage
log_write("debug", "service_usage_traffic", "Total raw traffic usage for " . $this->date_start . " until " . $this->date_end . " is " . $this->data["total"]["total"] . " bytes");
} else {
/*
Connect to External SQL database
External DBs are common with larger teleco providers since it allows easier storage, splicing and archiving of usage information
for data traffic services.
*/
switch ($GLOBALS["config"]["SERVICE_TRAFFIC_DB_TYPE"]) {
case "mysql_netflow_daily":
/*
MODE: mysql_netflow_daily
In this mode, there are netflow tables for each day which we need to read through and aggregate data from, typically
this is done so that busy ISPs don't end up with massive monthly/yearly tables.
eg:
traffic_20110420
traffic_20110421
traffic_20110422
TODO: Currently all traffic is just assigned against type any/*, this should be upgraded to properly support
the different traffic types.
*/
log_write("debug", "service_usage_traffic", "Processing external database mysql_netflow_daily");
/*
Connect to external database
*/
$obj_traffic_db_sql = new sql_query();
if (!$obj_traffic_db_sql->session_init("mysql", $GLOBALS["config"]["SERVICE_TRAFFIC_DB_HOST"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_NAME"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_USERNAME"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_PASSWORD"])) {
log_write("error", "service_usage_traffic", "Unable to establish a connection to the external traffic DB, unable to run data usage processing.");
return 0;
}
/*
Workout the date range, since we need to query a different table for each day
TODO: this would be nice as a generic function?
*/
$tmp_date = $this->date_start;
$date_range = array();
$date_range[] = $this->date_start;
while ($tmp_date != $this->date_end) {
$tmp_date = explode("-", $tmp_date);
$tmp_date = date("Y-m-d", mktime(0, 0, 0, $tmp_date[1], $tmp_date[2] + 1, $tmp_date[0]));
$date_range[] = $tmp_date;
}
for ($i = 0; $i < count($date_range); $i++) {
// strip "-" charactor
$date_range[$i] = str_replace("-", "", $date_range[$i]);
}
/*
We work out the usage by fetching the totals for each IPv4 address belonging to this
service and aggregating the total.
*/
// make sure we have the array of IPv4 addresses
if (!$this->data_ipv4) {
$this->load_data_ipv4();
}
// blank current total
//.........这里部分代码省略.........