Insert into mySQL Database throw PHP elements without duplicating them
I am working on a small Project with Unity3D and i want to post on mySQL Database players Name and Score. The php Script takes Values from some c#. I can't get it to have per Name only one Row on Database. The Script does Post now but only like this Name Score
What I really want is just
maku 20
try { $dbh = new PDO('mysql:host='. $hostname .';dbname='. $database, $username, $password); } catch(PDOException $e) { echo '
An error has ocurred.
', $e->getMessage() ,''; } $del= $dbh->prepare("SELECT * FROM scores WHERE name=:name");
if($del->rowCount()>0)
{
$sth = $dbh->prepare("UPDATE scores SET score=:score WHERE name=:name");
}else
if($del->rowCount()==0)
{
$sth = $dbh->prepare("INSERT INTO scores VALUES (null, :name, :score)");
}
try {
$sth->execute($_GET);
} catch(Exception $e) {
echo '<h1>An error has ocurred.</h1><pre>', $e->getMessage() ,'</pre>';
}
Is it possible?
链接地址: http://www.djcxy.com/p/69176.html上一篇: 需要帮助诊断php错误