www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP Stops Without Any Hint

  1. #1
    Join Date
    Feb 2011
    Posts
    83

    PHP Stops Without Any Hint

    Hello every one,

    I have a code stop without any error or info:
    A php code inserts records to a MyQL table successfully. The insert is very simple: three integers of a table. Below is the code:
    Code:
    $inssql	= "INSERT INTO pppv(addrs, addre, LcID) VALUES({$ads}, {$ade},{$LcID})";
    echo "i={$i} " . $inssql . "<br>";
    $result = mysqli_query($con,$inssql);
    if (!$result) {
       trigger_error("Error: f-city.php query cities - {$inssql} - " . mysqli_error($con) . "<br>", E_USER_ERROR);
    } 
    echo "i={$i} result={$result} " . $inssql . "<br>";
    Below is the last two results from one run:
    Code:
    i=2766 INSERT INTO pppv(addrs, addre, LcID) VALUES(36874, 368999,5 )
    i=2766 result=1 INSERT INTO pppv(addrs, addre, LcID) VALUES(363744, 368639,5 )
    i=2766 "36863744","36863999","5"
    i=2767 INSERT INTO pppv(addrs, addre, LcID) VALUES(368640, 365023,554 )
    For a normal run, there are three output lines, two lines are produced by the above code, another after these two line. From the above output, 2766th record is a success one. But for 2767th, even it's inserted into table successfully (it's in the table, I checked), and no error log in the log, ii stopped before the 2nd echo. This keeps for every one, this run processed 2768 records, another for 3040 records, .... What is the problem for code to stop?

    Thanks,
    Last edited by wow; 10-05-2014 at 01:11 PM.

  2. #2
    1) check your server logs... not all fatal's have output.

    2) turn on verbose/complete error reporting.
    Code:
    error_reporting(E_ALL);
    3) STOP wasting code on double quotes and string additions on cases where they are slower and/or inappropriate.

    4) for example, you're using mysqli, USE IT -- one of the entire reasons to use mysqli or PDO instead of mysql_ is to not be blindly dumping variables into query strings directly. (lemme guess, still using the _real_escape_string nonsense?!?)

    Also a lot of what you are doing would only need to be done ONCE if you were using prepared queries like a good little doobie instead of the outdated, outmoded, insecure and bandwidth (yes I said bandwidth) wasting practice of blindly dumping values into your query string. (particularly with the needlessly convoluted string method you're using of double quotes with brackets)

    Code:
    $statement = $con->prepare('
    	INSERT INTO pppv (
    		addrs, addre, LcID
    	) VALUES (
    		?, ?, ?
    	)
    ');
    
    $statement->bind_param('sss', $ads, $ade, $LcID);
    
    // start looping values here if doing this more than once with different values
    
    echo $i, ' ', $ads, ' ', $ade, ' ', $LcID, ' - ';
    
    if ($statement->execute()) {
    	echo 'Added Successfully<br />';
    } else {
    	echo 'Failed: ', $con->error(), '<br />';
    }
    
    // end of loop for multiple values
    
    $stmt->close();
    Should be what you are doing if you're going to use mysqli -- otherwise you might as well go back to 2006 and use the mysql_ functions.

    Prepare/exec is nice since the query is sent separate from the data, allowing you to perform multiple identical queries while only sending the data to the SQL engine... and since it's separate from the query it's auto-sanitized for free.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles