Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:05:01+00:00 2026-06-11T06:05:01+00:00

I have this php codes which have a lot of mysql_query and or die

  • 0

I have this php codes which have a lot of mysql_query and or die ( mysql_error() )

how can i lessen the mysql_query or is the or die ( mysql_error() ) really need for my codes?

Im going to paste my codes here.

$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() );
}*/

if you noticed lots of query called.
its a game application that fetch all the records and update.
is there a way that we can clean the codes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:05:02+00:00Added an answer on June 11, 2026 at 6:05 am

    If this code is working and years of bug fixes you should not change it as little as possible.
    I recommend you grep through you code and find ‘mysql_query’ calls. And replace it with a similar function first.

    mysql_query( some text here ) or die(mysql_error());
    

    should be replaced with

    handle_query( some text here )
    

    and handle_query function should be defined as

    function handle_query($query){
        mysql_query( $query) or die(mysql_error());
    }
    

    After that run your tests. If all goes well. Change handle_query function body.

    how can i lessen the mysql_query or is the or die ( mysql_error() ) really need for my codes?

    You can use sed/grep. Assuming your code is in junk_code.php you can use this command to get read of those or die (mysql_error());

    sed 's/mysql_query/handle_query/g'  junk_code | sed 's/\s*or\s*die\s*(\s*mysql_error(\s*)\s*)\s*//g'
    

    But dont forget to take backup before playing with such legacy code. These codes has long years experiences in it. May be lots of bug fixes. You surely dont want to break it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which will include template.php file from inside each of these
I have this code which is passed to Paypal checkout: <?php foreach ($paypalBasket as
Possible Duplicate: php loop through associative arrays i have this piece of code which
I have this PHP code to highlight the Query on search results. if (isset($_REQUEST['k'])){
I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
I have this PHP code in a loop for every post on the admin
i have this php code and keep on getting errors upon fixing each error.
I have this php code $filename = verbs.php; // http://alylores.x10.mx/vega/verbs2.php $handle = fopen($filename, r);
i have this PHP code, and a DataBase with Question, answer1, answer2, Question_id well,
I have this piece of php - mysql code: When a user tagged in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.