טוב אני חזרתי טיפה לקודד אחרי שנים שלא נגעתי בזה והחלטתי לבנות מערכת מסויימת עם שימוש ב-OOP... בכל אופן התחלתי עם בניית מחלקה למסד נתונים אבל לא משנה אם זה מתחבר או לא, שאני מציב תנאי הוא תמיד יכתוב לי שהוא מחובר! ושמתי משתמש וסיסמא שגויים ועדיין... בכל אופן הנה חלק מהקוד: class dbConn { var $dbConnErrors = array( 'connect' => '{dbConn} Could not connect to database: ', 'select_db' => '{dbConn} Could not select db: ', 'query' => '{dbConn} Could not execute query: ', 'fetch_object' => '{dbConn} Could not fetch objects from query: ', 'fetch_row' => '{dbConn} Could not fetch row from query: ', 'fetch_array' => '{dbConn} Could not fetch array from query: ', 'num_rows' => '{dbConn} Could not number the rows from query: ' ); var $link = false; var $host, $name, $user, $pass; var $sql, $rows, $qry; var $obj, $row, $arr; var $intLimit, $intOffset, $strType; function dbConn ( $user, $pass, $host = 'localhost' ) { $this->host = $host; $this->user = $user; $this->pass = $pass; // check if a connection exists, if so exit if ( $this->link ) exit; // try connecting to the specified database, // link = true in case of success - dies and displays an error in case of failure $this->link = @mysql_connect ( $this->host, $this->user, $this->pass ); if ( !$this->link ) { die ( '{$dbConnErrors[0]}' . mysql_error() ); return false; } return $this->link; }
|
מישהו יכול להאיר את עיני?
תודה :]
