Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Session in Class
    primarykey
    data
    text
    <pre><code>&lt;? session_start(); class DB_MSSQL { protected $Host; protected $Database; protected $User; protected $Password; protected $Link_ID = 0; protected $Query_ID = 0; protected $Record = array(); protected $Row = 0; protected $Errno = 0; protected $Error = ""; protected $Halt_On_Error = "yes"; protected $Auto_Free = 1; protected $PConnect = 0; function _construct(){ $this-&gt;Host = $_SESSION['SQLIP']; $this-&gt;Database = $_SESSION['SQLDB']; $this-&gt;User = $_SESSION['SQLUSER']; $this-&gt;Password = $_SESSION['SQLPASS']; } function DB_MSSQL($query = "") { if($query) { $this-&gt;query($query); } } function connect() { if ( 0 == $this-&gt;Link_ID ) { if(!$this-&gt;PConnect) { $this-&gt;Link_ID = mssql_connect($this-&gt;Host, $this-&gt;User, $this-&gt;Password); } else { $this-&gt;Link_ID = mssql_pconnect($this-&gt;Host, $this-&gt;User, $this-&gt;Password); } if (!$this-&gt;Link_ID) $this-&gt;connect_failed("connect ($this-&gt;Host, $this-&gt;User, \$Password) failed"); else if (!mssql_select_db($this-&gt;Database, $this-&gt;Link_ID)) { $this-&gt;connect_failed("cannot use database ".$this-&gt;Database); } } } function connect_failed($message) { $this-&gt;Halt_On_Error = "yes"; $this-&gt;halt($message); } function free_result(){ mssql_free_result($this-&gt;Query_ID); $this-&gt;Query_ID = 0; } function query($Query_String) { /* No empty queries, please, since PHP4 chokes on them. */ if ($Query_String == "") /* The empty query string is passed on from the constructor, * when calling the class without a query, e.g. in situations * like these: '$db = new DB_Sql_Subclass;' */ return 0; if (!$this-&gt;Link_ID) $this-&gt;connect(); // printf("&lt;br&gt;Debug: query = %s&lt;br&gt;\n", $Query_String); $this-&gt;Query_ID = mssql_query($Query_String, $this-&gt;Link_ID); $this-&gt;Row = 0; if (!$this-&gt;Query_ID) { $this-&gt;Errno = 1; $this-&gt;Error = "General Error (The MSSQL interface cannot return detailed error messages)."; $this-&gt;halt("Invalid SQL: "); } return $this-&gt;Query_ID; } function next_record() { if ($this-&gt;Record = mssql_fetch_row($this-&gt;Query_ID)) { // add to Record[&lt;key&gt;] $count = mssql_num_fields($this-&gt;Query_ID); for ($i=0; $i&lt;$count; $i++){ $fieldinfo = mssql_fetch_field($this-&gt;Query_ID,$i); $this-&gt;Record[strtolower($fieldinfo-&gt;name)] = $this-&gt;Record[$i]; } $this-&gt;Row += 1; $stat = 1; } else { if ($this-&gt;Auto_Free) { $this-&gt;free_result(); } $stat = 0; } return $stat; } function seek($pos) { mssql_data_seek($this-&gt;Query_ID,$pos); $this-&gt;Row = $pos; } function metadata($table) { $count = 0; $id = 0; $res = array(); $this-&gt;connect(); $id = mssql_query("select * from $table", $this-&gt;Link_ID); if (!$id) { $this-&gt;Errno = 1; $this-&gt;Error = "General Error (The MSSQL interface cannot return detailed error messages)."; $this-&gt;halt("Metadata query failed."); } $count = mssql_num_fields($id); for ($i=0; $i&lt;$count; $i++) { $info = mssql_fetch_field($id, $i); $res[$i]["table"] = $table; $res[$i]["name"] = $info-&gt;name; $res[$i]["len"] = $info-&gt;max_length; $res[$i]["flags"] = $info-&gt;numeric; } $this-&gt;free_result(); return $res; } function affected_rows() { // Not a supported function in PHP3/4. Chris Johnson, 16May2001. // return mssql_affected_rows($this-&gt;Query_ID); $rsRows = mssql_query("Select @@rowcount as rows", $this-&gt;Link_ID); if ($rsRows) { return mssql_result($rsRows, 0, "rows"); } } function num_rows() { return mssql_num_rows($this-&gt;Query_ID); } function num_fields() { return mssql_num_fields($this-&gt;Query_ID); } function nf() { return $this-&gt;num_rows(); } function np() { print $this-&gt;num_rows(); } function f($Field_Name) { return $this-&gt;Record[strtolower($Field_Name)]; } function p($Field_Name) { print $this-&gt;f($Field_Name); } function halt($msg) { if ("no" == $this-&gt;Halt_On_Error) return; $this-&gt;haltmsg($msg); if ("report" != $this-&gt;Halt_On_Error) die("Session halted."); } function haltmsg($msg) { printf("&lt;p&gt;Server have a critical error!&lt;br&gt;&lt;br&gt;&lt;br&gt;We are very sorry for any inconvenience!&lt;br&gt;&lt;br&gt;\n", $msg); printf("&lt;b&gt;MSSQL Error&lt;/b&gt;: %s (%s)&lt;/p&gt;\n", $this-&gt;Errno, $this-&gt;Error); } } ?&gt; </code></pre> <p>Faild to connect.. if i put $Host;$Database;$User;$Password; manually is work fine. but with constructor can't connect. ($_SESSION have correct value)</p> <p>But i don't know how to echo $obj->Host,Password,user,etc.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload