הרשם שאלות ותשובות רשימת חברים לוח שנה חיפוש הודעות מהיום סמן פורומים כנקראו

   
|!|

 
 
כלים לאשכול תצורת הצגה
Prev הודעה קודמת   הודעה הבאה Next
ישן 13-08-06, 12:45   # 5
lalamen
חבר פורום
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
גיל: 34
הודעות: 328

lalamen לא מחובר  

מצאתי לך מחלקה של DATEBASE תסתכל איך הם עשו

PHP קוד:
class mysql {

  function 
Connect($host$name$pass$db){

  
$connection mysql_connect("$host",
  
"$name",
  
"$pass");
  
mysql_select_db("$db"$connection);

  }
//ends the connection function

  
function Close(){

  
mysql_close($this->connection);

  }
//ends the close function

  
function FetchRow($query){
  
$rows mysql_fetch_row($query);
  return 
$rows;
  }

  function 
FetchArray($query){
  
$array mysql_fetch_array($query);
  return 
$array;
  }

  function 
FetchNum($query){
  
$num mysql_num_rows($query);
  return 
$num;
  }

  function 
Query($sql){
  
$query mysql_query($sql) or die(mysql_error());
  return 
$query;
  }
//ends the query function

  
}//ends the class 
דוגמא לשימוש במחלקה

PHP קוד:
 include("mysql_class.php");

  
$DB = new mysql();

  
$host "localhost";
  
$name "username";
  
$pass "password";
  
$db "dbname";

  
$connection $DB->Connect($host$name$pass$db);

  
//define an SQL statement and execute it
  
$sql "SELECT title,author FROM news";
  
$query $DB->Query($sql);

  
//fetch a single row and output it
  
$newsrow $DB->FetchRow($query);
  
$title $newsrow[0];
  
$author $newsrow[1];
  echo 
"<b>Single Row</b><br /><br />Title: $title<br>
  Author: $author<br><br>"
;

  
//output all rows from the statement
  
while($array $DB->FetchArray($query)){
  
extract($array);
  echo 
"<b>All rows</b><br /><br />Title: $title<b>
  Author: $author<br />"
;
  }

  
//find the number of rows
  
$num $DB->FetchNum($query);
  echo 
"Number of rows: $num";

  
//close the connection
  
$DB->Close(); 
  Reply With Quote
 

חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים)
 

כלים לאשכול
תצורת הצגה

חוקי פירסום
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is מופעל
סמיילים הם מופעל
[IMG] קוד מופעל
קוד HTML מכובה

קפיצה לפורום


כל הזמנים הם GMT +2. הזמן כעת הוא 11:36.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ