PHP

[email protected]


คลาสฐานข้อมูล MySQL ด้วย PHP

<?php

//under PHP5 on Windows

class mysql_array
{

 public function __construct( $s_host , $s_user , $s_pass , $s_db )
 {
  $this -> r_conn = mysql_connect ( $s_host , $s_user , $s_pass ) or die ( mysql_error ( ) ) ;
  mysql_select_db ( $s_db ) ;
 }

 private function array_make ( $s_sql , $i_type )
 {
  $r_rs = mysql_query ( $s_sql , $this -> r_conn ) or die ( mysql_error ( ) ) ;
  while ( $a_col = mysql_fetch_array ( $r_rs , $i_type ) )
   {
    $a_rs [ ] = $a_col ;
   }
  mysql_free_result ( $r_rs ) ;
  return ( $a_rs ) ;
 }

 public function array_logic ( $s_sql )
 {
  $a_rs = $this -> array_make ( $s_sql , MYSQL_NUM ) ;
  return ( $a_rs ) ;
 }

public function array_assoc ( $s_sql )
{
 $a_rs = $this -> array_make ( $s_sql , MYSQL_ASSOC ) ;
 return ( $a_rs ) ;
}

 public function array_both ( $s_sql )
 {
  $a_rs = $this -> array_make ( $s_sql , MYSQL_BOTH ) ;
  return ( $a_rs ) ;
 }
}

$o_mysql = new mysql_array ( 'localhost' , 'user' , 'pass' , 'db' ) ;
$s_sql = "SHOW TABLES" ;
$a_rs = $o_mysql -> array_assoc ( $s_sql ) ;

echo '<pre>' ;
print_r ( $a_rs ) ;
?>
 สร้างเมือวันที่ :03-07-2548  ที่มา.www.php.net 

ตัวอย่าง

<?php
class connecttion
{

 function connecttion( $s_host , $s_user , $s_pass , $s_db )
 {
  $this -> db_connect = mysql_connect ( $s_host , $s_user , $s_pass ) or die ( mysql_error ( ) ) ;
  mysql_select_db ( $s_db ) ;
 }
}

$conn_mysql = new connecttion ( 'localhost' , 'user' , 'pass' , 'db' ) ;
?>

เกี่ยวกับเรา | Site Map | Privacy Policy | ติดต่อเรา | ©2005 Company Name

Hosted by www.Geocities.ws

1