1. char(60)
2. varchar(8192)
3. longtext
II. boolean
1. enum('N', Y') 혹은 enum('FUNCTION', 'PROCEDURE')
2. set('Select', 'Insert', 'Update')
III. 숫자
1. bigint(21) unsigned 혹은 bitint(10)
IV. 시간
1. datetime
- 값 : 2011-05-19 10:06:34
2. timestamp(14)
$con = @new mysqli($GLOBALS['gServerName'], $GLOBALS['gUserId'],
$GLOBALS['gPassword'], $GLOBALS['gDatabase']);
if ($con->connect_errno) {
printf("%d : %s <br/>", $con->connect_errno, $con->connect_error);
exit();
}
$userId = "skanddh";
$sql = "select * from User where userId = " . $userId;
$result = $con->query($sql);
$rowCount = $result->num_rows;
for($i=0; $i<$rowCount; $i++) {
$row = $result->fetch_assoc();
print("userId = " . htmlspecialchars(stripslashes($row['userId'])) .
"<br/>");
print("userName = " . htmlspecialchars(stripslashes($row['userName'])) .
"<br/>");
print("age = " . htmlspecialchars(stripslashes($row['age'])) . "<br/>");
}
for($i=0; $i<$rowCount; $i++) {
$row = $result->fetch_object();
print("userId = " . htmlspecialchars(stripslashes($row->userId)) .
"<br/>");
print("userName = " . htmlspecialchars(stripslashes($row->userName)) .
"<br/>");
print("age = " . htmlspecialchars(stripslashes($row->age)) . "<br/>");
}
$result->free();
$con->close();
$userId = 'me';
$userName = 'john';
$age = 30;
$sql = " insert into User (userId, userName, age) " .
" values ('" . $userId . "', '". $userName . "', ". $age . ") ";
$con->query($sql);
printf("%d user inserted into database.<br/>", $con->affected_rows);
$con->commit();
$sql = " insert into User (userId, userName, age) " .
" values (?, ?, ?) ";
$stmt = $con->prepare($sql);
$stmt->bind_param("ssi", $userId, $userName, $age);
$stmt->execute();
printf("%d user inserted into database.<br/>", $con->affected_rows);
$stmt->close();
$sql = " select userId, userName, age from User ";
if ( $stmt = $con->prepare($sql) ) {
$stmt->execute();
if ($stmt->errno) {
printf("execute() >> %d : %s <br/>",$stmt->errno, $stmt->error);
}
$stmt->bind_result($rUserId, $rUserName, $rAge);
$count = 0;
while ($stmt->fetch()) {
$count++;
print("userId = " . htmlspecialchars(stripslashes($rUserId)) .
"<br/>");
print("userName = " . htmlspecialchars(stripslashes($rUserName)) .
"<br/>");
print("age = " . htmlspecialchars(stripslashes($rAge)) . "<br/>");
}
printf("%d row seleted. <br/>", $count);
$stmt->close();
}
class Point {
private $x;
private $y;
public function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
public function __get($name) {
return $this->$name;
}
public function __set($name, $value) {
$this->$name = $value;
}
public function display() {
print("\$this->x = " . $this->x . "<br/>");
print("\$this->y = " . $this->y . "<br/>");
}
}
$point = new Point(3, 5);
print($point->x); // 3
print($point->y); // 5
$point->x = 7;
print($point->x); // 7
$point->display();
class Rectangle extends Point {
private $width;
private $height;
public function __construct($x, $y, $width, $height) {
parent::__construct($x, $y);
$this->x = $x;
$this->y = $y;
}
}
$rectangle = new Rectangle(10, 20, 100, 200);
print($rectangle->x); // 10interface Displayable {
public function display();
}
class WebPage implements Displayable {
public function display() {
print("Hello World!! <br/>");
}
}
$page = new WebPage();
$page->display();
class Math {
const pi = 3.14159;
public static function squared($input) {
return $input * $input;
}
}
print("Math::pi = " . Math::pi . "<br/>");
print("Math::squared(8) = " . Math::squared(8) . "<br/>");
abstract class A {
public abstract function operationX($param1, $param2);
}
class ConcreteA extends A {
public function operationX($param1, $param2) {
return $param1 + $param2;
}
}
$a = new ConcreteA();
print($a->operationX(3, 4) . "<br/>");