<ol
class
=
"dp-xml"
>
<li
class
=
"alt"
><span><span
class
=
"tag"
><span> ? </span></span></span></li>
<li><span>
require_once
(
"DB.php"
); </span></li>
<li
class
=
"alt"
>
<span>$</span><span
class
=
"attribute"
>userName</span><span> = </span><span
class
=
"attribute-value"
>
'root'
</span><span>; </span>
</li>
<li>
<span>$</span><span
class
=
"attribute"
>password</span><span> = </span><span
class
=
"attribute-value"
>
'123456'
</span><span>; </span>
</li>
<li
class
=
"alt"
>
<span>$</span><span
class
=
"attribute"
>hostName</span><span> = </span><span
class
=
"attribute-value"
>
'localhost'
</span><span>; </span>
</li>
<li>
<span>$</span><span
class
=
"attribute"
>dbName</span><span> = </span><span
class
=
"attribute-value"
>
'test'
</span><span>; </span>
</li>
<li
class
=
"alt"
>
<span>$</span><span
class
=
"attribute"
>dsn</span><span> = </span><span
class
=
"attribute-value"
>
"mysql://$userName:<br>$password@$hostName/$dbName"
</span><span>; </span>
</li>
<li>
<span>$</span><span
class
=
"attribute"
>dbCon</span><span> = </span><span
class
=
"attribute-value"
>DB</span><span>::connect(
$dsn
); </span>
</li>
<li
class
=
"alt"
><span>
if
(DB::isError(
$dbCon
)) { </span></li>
<li>
<span>
die
(
$dbCon
-</span><span
class
=
"tag"
>></span><span>getMessage()); </span>
</li>
<li
class
=
"alt"
><span>} </span></li>
<li>
<span>$</span><span
class
=
"attribute"
>sql</span><span> = </span><span
class
=
"attribute-value"
>
"CREATE TABLE leapsoul ("
</span><span>. </span>
</li>
<li
class
=
"alt"
><span>
"`id` INT( 11 ) UNSIGNED NOT NULL ,"
. </span></li>
<li><span>
"`name` VARCHAR( 30 ) CHARACTER <br>SET gbk COLLATE gbk_chinese_ci NOT NULL ,"
. </span></li>
<li
class
=
"alt"
><span>
"`age` INT( 2 ) NOT NULL ,"
. </span></li>
<li><span>
"`birthday` VARCHAR( 30 ) CHARACTER <br>SET gbk COLLATE gbk_chinese_ci NOT NULL ,"
. </span></li>
<li
class
=
"alt"
><span>
"`sex` INT( 1 ) NOT NULL ,"
. </span></li>
<li><span>
"PRIMARY KEY ( `id` )"
. </span></li>
<li
class
=
"alt"
>
<span>
") </span><span class="
attribute
">ENGINE</span><span> = </span><span class="
attribute-value
">MYISAM</span><span> CHARACTER SET gbk <br>COLLATE gbk_chinese_ci"
; </span>
</li>
<li>
<span>$</span><span
class
=
"attribute"
>result</span><span> =
$dbCon
-</span><span
class
=
"tag"
>></span><span>query(
$sql
); </span>
</li>
<li
class
=
"alt"
><span>
if
(DB::isError(
$result
)) { </span></li>
<li>
<span>
die
(
$result
-</span><span
class
=
"tag"
>></span><span>getMessage()); </span>
</li>
<li
class
=
"alt"
><span>} </span></li>
<li>
<span>$</span><span
class
=
"attribute"
>sql</span><span> = </span><span
class
=
"attribute-value"
>
"insert into leapsoul(id,name,<br>age,birthday,sex) values(1,'leapsoul',1,<br>'2009-05-13',1),(2,'leapsoul',1,'2009-05<br>-13',1),(3,'leapsoul',1,'2009-05-13',1)"
</span><span>; </span>
</li>
<li
class
=
"alt"
>
<span>$</span><span
class
=
"attribute"
>result</span><span> =
$dbCon
-</span><span
class
=
"tag"
>></span><span>query(
$sql
); </span>
</li>
<li><span>
if
(DB::isError(
$result
)) { </span></li>
<li
class
=
"alt"
>
<span>
die
(
$result
-</span><span
class
=
"tag"
>></span><span>getMessage()); </span>
</li>
<li><span>} </span></li>
<li
class
=
"alt"
>
<span>
$dbCon
-</span><span
class
=
"tag"
>></span><span>setFetchMode(DB_FETCHMODE_ASSOC); </span>
</li>
<li>
<span>$</span><span
class
=
"attribute"
>sql</span><span> = </span><span
class
=
"attribute-value"
>
"select * from leapsoul"
</span><span>; </span>
</li>
<li
class
=
"alt"
>
<span>$</span><span
class
=
"attribute"
>result</span><span> =
$dbCon
-</span><span
class
=
"tag"
>></span><span>query(
$sql
); </span>
</li>
<li><span>
if
(DB::isError(
$result
)) { </span></li>
<li
class
=
"alt"
>
<span>
die
(
$result
-</span><span
class
=
"tag"
>></span><span>getMessage()); </span>
</li>
<li><span>} </span></li>
<li
class
=
"alt"
>
<span>
for
($</span><span
class
=
"attribute"
>i</span><span>=</span><span
class
=
"attribute-value"
>0</span><span>;
$i
</span><span
class
=
"tag"
><span>
$result
-</span><span
class
=
"tag"
>></span><span>numRows();
$i
++) </span></span>
</li>
<li><span>{ </span></li>
<li
class
=
"alt"
>
<span>$</span><span
class
=
"attribute"
>info</span><span> = &
$result
-</span><span
class
=
"tag"
>></span><span>fetchRow(); </span>
</li>
<li><span>
echo
"name:"
.
$info
[
'name'
]; </span></li>
<li
class
=
"alt"
>
<span>
echo
"birthday:"
.
$info
[
'birthday'
].
"</span><span class="
tag
"><span class="
tag-name
">br</span><span class="
tag
">></span><span>"
; </span></span>
</li>
<li><span>} </span></li>
<li
class
=
"alt"
>
<span>
$result
-</span><span
class
=
"tag"
>></span><span>free(); </span>
</li>
<li>
<span>
$dbCon
-</span><span
class
=
"tag"
>></span><span>disconnect(); </span>
</li>
<li
class
=
"alt"
><span>} </span></li>
</ol>