mysql_query
我有这个 php 代码,其中有很多or die ( mysql_error() )
我怎样才能减少 mysql_query 或者我的代码真的需要 or die ( mysql_error() ) 吗?
我要在这里粘贴我的代码。
$sqlScore = "UPDATE game SET currentTurn = '1', remainingTiles='".$remainingTiles."' WHERE gameID = '".$gameID."'";
mysql_query( $sqlScore ) or die ( mysql_error() );
$ScoreSelect = set_mysql( "SELECT * FROM game WHERE gameID = '".$gameID."'" );
$up_gameID = $ScoreSelect['gameID'];
$set_p1 = $ScoreSelect['player1'];
// CHECK IF GAMEID EXIST FOR SCORE
$checkData = mysql_query( "SELECT * FROM score WHERE gameID = '".$gameID."' " ) or die ( mysql_error() );
$rcd = mysql_fetch_array( $checkData );
$rcd['gameID'] == $gameID
? mysql_query( "UPDATE score SET score = '".$score."' WHERE gameID = '".$gameID."' " ) or die ( mysql_error() )
: mysql_query( "INSERT INTO score VALUE( '', '".$gameID."', '".$player1."', '".$score."')" ) or die ( mysql_error() );
// INSERT SQL WORD DATA
$sqlWD = mysql_query( "INSERT INTO word_data VALUE( '', '".$gameID."', '', '".$worddata."')" ) or die ( mysql_error() );
// CHECK FOR TILE
$sqlCheckRow = mysql_query( "SELECT * FROM wctilerack WHERE gameID = '".$up_gameID."' AND email = '".$up_email_player1."' " ) or die ( mysql_error() );
if ( mysql_num_rows( $sqlCheckRow ) == "1" ) {
// INSERT wctilerack
$sqlTileUP = mysql_query( "UPDATE wctilerack SET tiles = '$playerRack' WHERE gameID = '".$up_gameID."' AND email = '".$up_email_player1."' ") or die ( mysql_error() );
} else {
// INSERT wctilerack
$sqlTileINSERT = mysql_query( "INSERT INTO wctilerack VALUE('', '".$up_gameID."', '".$up_email_player1."', '$playerRack' ) ") or die ( mysql_error() );
}
// UPDATE lastPlayed
$sqlUpdatePlayed = mysql_query( "UPDATE user SET lastPlayed=NOW() WHERE email = '$up_email_player1' " ) or die ( mysql_error() );
// UPDATE word
$sqlUpdateWord = mysql_query( "UPDATE game SET lastWord = '".$xword[2]."', lastPoints='".$score."' WHERE gameID = '$up_gameID' " ) or die ( mysql_error() );
//$sqlInsertWord = mysql_query( "INSERT INTO word_data VALUE( '', '".$up_gameID."', '', '".$xword[2]."' )" ) or die ( mysql_error() );
/*$sqlCheckSK = mysql_query( "SELECT * FROM gameTileSkins WHERE gameID = '$gameID' AND email = '$up_email_player1' " ) or die ( mysql_error() );
if ( mysql_num_rows( $sqlCheckSK ) == '1' ) {
$skUP = mysql_query( "UPDATE gameTileSkins SET tileSkin='$tileSkinID' WHERE gameID = '$gameID' AND email = '$up_email_player1' " ) or die ( mysql_error() );
} else {
// INSERT gameTileSkins
$sqlSK = mysql_query( "INSERT INTO gameTileSkins VALUE('', '$gameID', '$up_email_player1', '$tileSkinID')" ) or die ( mysql_error() );
}*/
如果您注意到调用了很多查询。它是一个获取所有记录并更新的游戏应用程序。有没有办法可以清理代码。