Jump to content

statements per call?


woodsonoversoul

Recommended Posts

I was told the PHP MySQL library will only execute one statement per call to mysql_query. Is this true and could this be affecting a line of code like this?

 

// if id provided, then delete that record
if (isset($_GET['id'])) {
    // create query to delete record
    $query = "DELETE FROM purchase WHERE sale_id = ".$_GET['id'];
    
    // run the query
    mysql_query($query);

 

Help is appreciated, I'm getting error messages

Link to comment
https://forums.phpfreaks.com/topic/65467-statements-per-call/
Share on other sites

Cool, I can see why that would work better. My real question is (and this is kind of sneaky, I know), why would I get these error messages:

 

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'www-data'@'localhost' (using password: NO) in /var/www/spindex/display.php on line 31

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/spindex/display.php on line 31

1 row(s) affected

 

when I run this page:

 

<?php

//include file containing login information
include 'db.inc';

// create mysqli object
// open connection
$mysqli = new mysqli($host, $user, "", $db);

// check for connection errors
if (mysqli_connect_errno()) {
    die("Unable to connect!");
}

// if id provided, then delete that record
if (isset($_GET['id'])) {
    // create query to delete record
     $query = "DELETE FROM purchase WHERE sale_id = '{$_GET['id']}'";
    
    // run the query
    mysql_query($query);
    
// execute query
    if ($mysqli->query($query)) {
    // print number of affected rows
    echo $mysqli->affected_rows." row(s) affected";
    }
    else {
    // print error message
    echo "Error in query: $query. ".$mysqli->error;
    }
}
// query to get records
$query = "SELECT * FROM purchase";

// execute query
if ($result = $mysqli->query($query)) {
    // see if any rows were returned
    if ($result->num_rows > 0) {
        // yes
        // print them one after another
	echo $row[0];
	echo "<h1>category  location  price</h1>";
        echo "<table cellpadding=10 border=1>";
        while($row = $result->fetch_array()) {
            echo "<div id=\"navcontainer\">";
    	echo "<ul>";
            echo "<li><a href=#>".$row[2]."</li>";
    	echo "<li><a href=#>".$row[3]."</li>";
    	echo "<li><a href=#>$".$row[4]."</li>";
            echo "<li><a href=".$_SERVER['PHP_SELF']."?id=".$row[1].">x</a></li>";
            echo "</ul>";
		echo "</div>";
        }
    }

  // Compute total spent
  $sql = "SELECT SUM(price) AS total FROM purchase";
  if ($result = $mysqli->query($sql)) {
    if ($result->num_rows) {
      $row = $result->fetch_assoc();
      echo "You've spent a total of $" .$row['total'] ." this month";
    }
  } else {
    echo $mysqli->error;
    }
    // free result set memory
    $result->close();

}
else {
    // print error message
    echo "Error in query: $query. ".$mysqli->error;
}

// close connection
$mysqli->close();

?>

 

When I delete a row it goes away on the page, but I get the above error messages. I don't understand...

Link to comment
https://forums.phpfreaks.com/topic/65467-statements-per-call/#findComment-326911
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.