<span style=
"color: #000000"
>php
namespace
Home;
</span><span style=
"color: #008080"
>header</span>(
'content-type:text/html;charset=utf-8;'
<span style=
"color: #000000"
>);
</span><span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
use
</span><span style=
"color: #000000"
> \PDO;
</span><span style=
"color: #0000ff"
>
use
</span><span style=
"color: #000000"
> \PDOStatement;
</span><span style=
"color: #0000ff"
>
use
</span><span style=
"color: #000000"
> \PDOException;
</span><span style=
"color: #008000"
>
</span>
<span style=
"color: #0000ff"
>
class
</span><span style=
"color: #000000"
> Queue{
</span><span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
static
</span> <span style=
"color: #0000ff"
>
public
</span> <span style=
"color: #800080"
>
$container
</span>=<span style=
"color: #0000ff"
>
array
</span><span style=
"color: #000000"
>();
</span><span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
static
</span> <span style=
"color: #0000ff"
>
private
</span> <span style=
"color: #800080"
>
$pdo
</span><span style=
"color: #000000"
>;
</span><span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
public
</span> <span style=
"color: #0000ff"
>
function
</span> __construct(<span style=
"color: #800080"
>
$file
</span> =
'./mysql.ini'
){<span style=
"color: #008000"
>
<span style=
"color: #800080"
>
$dbini
</span> = <span style=
"color: #008080"
>
parse_ini_file
</span>(<span style=
"color: #800080"
>
$file
</span>,<span style=
"color: #0000ff"
>true</span><span style=
"color: #000000"
>);
</span><span style=
"color: #800080"
>
$driver
</span> = <span style=
"color: #800080"
>
$dbini
</span>[
'database'
][
'driver'
<span style=
"color: #000000"
>];
</span><span style=
"color: #008000"
>
<span style=
"color: #800080"
>
$dbname
</span> = <span style=
"color: #800080"
>
$dbini
</span>[
'database'
][
'dbname'
<span style=
"color: #000000"
>];
</span><span style=
"color: #800080"
>
$host
</span> = <span style=
"color: #800080"
>
$dbini
</span>[
'database'
][
'host'
<span style=
"color: #000000"
>];
</span><span style=
"color: #800080"
>
$port
</span> = <span style=
"color: #800080"
>
$dbini
</span>[
'database'
][
'port'
<span style=
"color: #000000"
>];
</span><span style=
"color: #008000"
>
<span style=
"color: #800080"
>
$dsn
</span> = <span style=
"color: #800080"
>
$driver
</span>.
':'
.
'dbname='
.<span style=
"color: #800080"
>
$dbname
</span>.
';host='
.<span style=
"color: #800080"
>
$host
</span>.
';port='
.<span style=
"color: #800080"
>
$port
</span><span style=
"color: #000000"
>;
</span><span style=
"color: #008000"
>
<span style=
"color: #800080"
>
$username
</span> = <span style=
"color: #800080"
>
$dbini
</span>[
'database'
][
'username'
<span style=
"color: #000000"
>];
</span><span style=
"color: #800080"
>
$password
</span> = <span style=
"color: #800080"
>
$dbini
</span>[
'database'
][
'password'
<span style=
"color: #000000"
>];
</span><span style=
"color: #800080"
>
$options
</span> = <span style=
"color: #800080"
>
$dbini
</span>[
'options'
];<span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
try
</span><span style=
"color: #000000"
>{
self</span>::<span style=
"color: #800080"
>
$pdo
</span> = <span style=
"color: #0000ff"
>
new
</span> PDO(<span style=
"color: #800080"
>
$dsn
</span>,<span style=
"color: #800080"
>
$username
</span>,<span style=
"color: #800080"
>
$password
</span>,<span style=
"color: #800080"
>
$options
</span><span style=
"color: #000000"
>);
</span><span style=
"color: #008000"
>
self::<span style=
"color: #800080"
>
$pdo
</span>->setAttribute(PDO::ATTR_ERRMODE,PDO::<span style=
"color: #000000"
>ERRMODE_EXCEPTION);
</span><span style=
"color: #0000ff"
>
try
</span><span style=
"color: #000000"
>{
</span><span style=
"color: #008000"
>
self::<span style=
"color: #800080"
>
$pdo
</span>-><span style=
"color: #008080"
>
exec
</span>(
'use queue'
<span style=
"color: #000000"
>);
}</span><span style=
"color: #0000ff"
>
catch
</span>(PDOException <span style=
"color: #800080"
>
$e
</span><span style=
"color: #000000"
>){
</span><span style=
"color: #0000ff"
>
echo
</span> <span style=
"color: #800080"
>
$e
</span>-><span style=
"color: #000000"
>getMessage();
}
}</span><span style=
"color: #0000ff"
>
catch
</span>(PDOException <span style=
"color: #800080"
>
$e
</span><span style=
"color: #000000"
>){
</span><span style=
"color: #0000ff"
>
echo
</span> <span style=
"color: #800080"
>
$e
</span>-><span style=
"color: #000000"
>getMessage();
}
}
</span><span style=
"color: #008000"
>
</span>
<span style=
"color: #0000ff"
>
public
</span> <span style=
"color: #0000ff"
>
function
</span> _unshift(<span style=
"color: #800080"
>
$data
</span> =<span style=
"color: #0000ff"
>
array
</span><span style=
"color: #000000"
>()){
</span><span style=
"color: #0000ff"
>
if
</span>(!<span style=
"color: #008080"
>
is_array
</span>(<span style=
"color: #800080"
>
$data
</span>) || <span style=
"color: #0000ff"
>
empty
</span>(<span style=
"color: #800080"
>
$data
</span>)){<span style=
"color: #0000ff"
>
return
</span> <span style=
"color: #0000ff"
>false</span><span style=
"color: #000000"
>;}
</span><span style=
"color: #800080"
>
$sql
</span> =
'default'
<span style=
"color: #000000"
>;
</span><span style=
"color: #0000ff"
>
foreach
</span>(<span style=
"color: #800080"
>
$data
</span> <span style=
"color: #0000ff"
>
as
</span> <span style=
"color: #800080"
>
$k
</span>=><span style=
"color: #800080"
>
$v
</span><span style=
"color: #000000"
>){
</span><span style=
"color: #800080"
>
$sql
</span> .=
',"'
.<span style="color: #800080
">$v</span>.'"
'<span style=
"color: #000000"
>;
}
</span><span style=
"color: #008000"
>
<span style=
"color: #800080"
>
$sql
</span> =
'insert into goods values('
.<span style=
"color: #800080"
>
$sql
</span>.
')'
<span style=
"color: #000000"
>;
</span><span style=
"color: #0000ff"
>
return
</span> @<span style=
"color: #008080"
>
array_unshift
</span>(self::<span style=
"color: #800080"
>
$container
</span>,<span style=
"color: #800080"
>
$sql
</span><span style=
"color: #000000"
>);
}
</span><span style=
"color: #008000"
>
</span>
<span style=
"color: #0000ff"
>
private
</span> <span style=
"color: #0000ff"
>
static
</span> <span style=
"color: #0000ff"
>
function
</span><span style=
"color: #000000"
> _pop(){
</span><span style=
"color: #0000ff"
>
try
</span>{<span style=
"color: #008000"
>
<span style=
"color: #800080"
>
$sql
</span> = <span style=
"color: #008080"
>
array_pop
</span>(self::<span style=
"color: #800080"
>
$container
</span><span style=
"color: #000000"
>);
self</span>::<span style=
"color: #800080"
>
$pdo
</span>-><span style=
"color: #008080"
>
exec
</span>(<span style=
"color: #800080"
>
$sql
</span><span style=
"color: #000000"
>);
</span><span style=
"color: #008000"
>
<span style=
"color: #800080"
>
$middle
</span> = self::<span style=
"color: #800080"
>
$container
</span><span style=
"color: #000000"
>;
</span><span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
while
</span>(<span style=
"color: #800080"
>
$middle
</span><span style=
"color: #000000"
>){
</span><span style=
"color: #800080"
>
$sql
</span> = <span style=
"color: #008080"
>
array_pop
</span>(<span style=
"color: #800080"
>
$middle
</span><span style=
"color: #000000"
>);
self</span>::<span style=
"color: #800080"
>
$pdo
</span>-><span style=
"color: #008080"
>
exec
</span>(<span style=
"color: #800080"
>
$sql
</span><span style=
"color: #000000"
>);
</span><span style=
"color: #008000"
>
self::<span style=
"color: #800080"
>
$container
</span> = <span style=
"color: #800080"
>
$middle
</span><span style=
"color: #000000"
>;
}
</span><span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
return
</span> self::<span style=
"color: #800080"
>
$pdo
</span>-><span style=
"color: #000000"
>lastInsertId();
}</span><span style=
"color: #0000ff"
>
catch
</span>(PDOException <span style=
"color: #800080"
>
$e
</span><span style=
"color: #000000"
>){
</span><span style=
"color: #0000ff"
>
return
</span> <span style=
"color: #800080"
>
$e
</span>-><span style=
"color: #000000"
>getMessage();
}
}
</span><span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
public
</span> <span style=
"color: #0000ff"
>
function
</span><span style=
"color: #000000"
> __destruct(){
</span><span style=
"color: #008000"
>
<span style=
"color: #0000ff"
>
if
</span>(self::<span style=
"color: #800080"
>
$container
</span><span style=
"color: #000000"
>){
self</span>::<span style=
"color: #000000"
>_pop();
}
}
}</span>