-
類別資料庫{
-
- var $host = NULL;
- var $username = NULL;
- var $password = NULL ;
- var $databaseName = NULL;
- var $link = NULL;
- var $queries = NULL;
- var $errors = NULL;
-
- var $ULLbase
- function __construct($host, $username, $password, $database) {
- $this->database($host, $username, $password, $database);
- }
-
- 函數資料庫($host, $username, $password, $database) {
- /*$this->database = array (
- "host" => $host,
- "使用者名稱" => $使用者名稱,
- "密碼" => $密碼,
- "資料庫" => $資料庫,
- "連結" => "查詢" => array (),
- "errors " => array ()
- );*/
-
- $this->host = $host;
- $this-> ;使用者名稱= $使用者名稱;
- $this-> password = $password;
- $this->databaseName = $database;
- $this->link = "";
- $this ->queries = array ();
- $this->errors = array ();
-
- $this->databaseExtras = new stdClass;
-
- $this-> link = mysql_connect($this->host, $this->username, $this-> password) or die("無法連線到資料庫");
- mysql_select_db($this->databaseName);
- }
-
- function justquery($sql) {
- $this->queries [] = $sql;
- return mysql_query($sql, $this->link);
- }
-
- function loadResult($sql) {
- if (!($cur = $ this->justquery($sql))) {
- return null;
- }
- $ret = null;
- if ($row = mysql_fetch_row( $cur )) {
- $ret = $row[0];
- }
- mysql_free_result( $cur );
- return $ret;
- }
-
- function loadFirstRow($sql) {
-
- function loadFirstRow($sql) {
- if (!(> if (!(> if (!(> if (!(>) $cur = $this->justquery($sql))) {
- return null;
- }
- $ret = null;
- if ($row = mysql_fetch_object( $cur )) {
- $ret = $row;
- }
- mysql_free_result( $cur );
- return $ret;
- }
-
- function insertid() {
- return mythis_ins_ return idsql(my)(),sql ->link );
- }
-
- function query($sql , $key = "", $returns = true, $batch = false) {
- $result = array ();
-
- switch ($batch) {
- 預設值:
- case true :
- foreach ($sql as $index => $query) {
- $this->queries[] = $ query;
- $answer = mysql_query($query, $this->link);
-
- if (!$answer) {
- $this->errors[] = mysql_error($this-> link);
- }
- else {
- if ($returns != false) {
- if (mysql_num_rows ($answer) > 0){
- while ($row = mysql_fansetch_object($ )) {
- if ($key != ""){
- $結果[$index][$row- >$key] = $row;
- }
- else {
- $結果[$index][] = $row;
- }
- }
- } else {}
- } else {}
- }
- }
- 中斷;
-
- case false:
- $this->queries[] = $sql;
- $answer = mysql_query( $sql, $this->link);
-
- if (!$answer) {
- $this->errors[] = mysql_error($this->link);
- $ result = false;
- }
- else {
- if ($returns != false) {
- if (mysql_num_rows($answer) >; 0){
- while ($row = mysql_fetch_object($answer)) {
- if ($key != ""){
- $result[$row> $result[$ ->$key] = $row;
- }
- else {
- $result[] = $row;
- }
- }
- } else {}
- }
- else {
- $result = true;
- }
- }
- break;
- }
-
- return $result;
- }
-
- return $result;
- }
-
- function loadObject( $sql, &$object ) {
- if ($object != null) {
- if (!($cur = $this->justquery($sql))) {
- return false ;
- } else {}
- if ($array = mysql_fetch_assoc( $cur )) {
- mysql_free_result( $cur );
- $this->bindArrayObject( $array, $object);
- return true;
- }
- else {
- return false;
- }
- }
- else {
- if ($cur = $this->justque($ ) )) {
- if ($object = mysql_fetch_object( $cur )) {
- mysql_free_result( $cur );
- return true;
- }
- else { $ ;
- return false;
- }
- }
- else {
- return false;
- }
- }
- }
-
- function bindarrayObject( & $obj) {
- if (!is_array( $array ) || !is_object( $obj )) {
- return (false);
- }
-
- foreach (get_object_vars(object_vars($object_vars(object_vars(object_vars(object_vars(object_vars(object_vars)(object_vars(object_) ) as $k => $v) {
- if( substr( $k, 0, 1 ) != '_' ) {
- $ak = $k;
- if (isset($array[ $ ak])) {
- $obj->$k = $array[$ak];
- }
- }
- }
-
- 回傳true;
- }
- }
-
- 函數格式CSVCell($data) {
- $useQuotes = false;
-
- $quotable = array (
- """ => """",
- "," = > ",",
- "n" =>; "n"
- );
-
- foreach ($quotable as $char => $repl) {
- if (eregi($ char , $data)) {
- $useQuotes = true ;
- } else {}
- }
-
- if ($useQuotes == true) {
- foreach ($quotable as $ char => $repl) {
- $data = str_replace($char, $repl, $data);
- }
-
- $data = """ 。$資料。""";
- }
- else {
-
- }
-
- 回傳$data;
} } ?>
} | ?>