- 클래스 데이터베이스 {
-
- var $host = NULL;
- var $username = NULL;
- var $password = NULL;
- var $databaseName = NULL;
- var $link = NULL;
- var $queries = NULL;
- var $errors = NULL;
-
- var $databaseExtras = NULL;
-
- function __construct($host, $username, $password, $database) {
- $this->database($host, $username, $password, $database);
- }
-
- 함수 데이터베이스($host, $username, $password, $database) {
- /*$this->database = array (
- "host" => $host,
- "사용자 이름" => $username,
- "password" => $password,
- "database" => $database,
- "link" => " => 배열(),
- "errors" => 배열()
- );*/
-
- $this->host = $host;
- $this-> ;username = $username;
- $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) 또는 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) {
- 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 mysql_insert_id( $this->link );
- }
-
- function query($sql , $key = "", $returns = true, $batch = false) {
- $result = array ();
-
- 스위치($batch) {
- 기본값:
- 케이스 true :
- foreach($sql을 $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_fetch_object($answer)) {
- if ($key != ""){
- $result[$index][$row- >$key] = $row;
- }
- else {
- $result[$index][] = $row;
- }
- }
- } else {}
- } else {}
- }
- }
- break;
-
- 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->$key] = $row;
- }
- else {
- $result[] = $row;
- }
- }
- } else {}
- }
- else {
- $result = true;
- }
- }
- break;
- }
-
- 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->bindArrayToObject( $array, $object);
- true 반환;
- }
- else {
- false 반환;
- }
- }
- else {
- if ($cur = $this->justquery($ sql)) {
- if ($object = mysql_fetch_object( $cur )) {
- mysql_free_result( $cur );
- return true;
- }
- else {
- $object = null ;
- false 반환;
- }
- }
- else {
- false 반환;
- }
- }
- }
-
- 함수 binArrayToObject( $array, &$obj) {
- if (!is_array( $array ) || !is_object( $obj )) {
- return (false);
- }
-
- foreach (get_object_vars($obj) as $k => $v) {
- if( substr( $k, 0, 1 ) != '_' ) {
- $ak = $k;
- if (isset($array[$ak])) {
- $obj->$k = $array[$ak];
- }
- }
- }
-
- return true;
- }
-
- 함수 형식CSVCell($data) {
- $useQuotes = false;
-
- $quotable = 배열(
- """ => """",
- "," => ",",
- "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 {
-
- }
-
- return $data;
- }
- }
- ?>
제조대码
|