none
[PHP][Web Apps] WebApp with MySQL - no INSERT option RRS feed

Answers

  • Which PHP MySQL operations lib you use? As I have a simple test on Azure Web app, and which works fine with "INSERT" query.

    Here is the test code snippet for your information:

    $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    try {
        $stmt = $DBH->prepare("INSERT INTO user (`name`, `age`) VALUES (?, ?)");
        $stmt->execute(array('somebody',25));
        $affected_rows = $stmt->rowCount();
        var_dump($affected_rows);
    }
    catch(Exception $e) {
        die(var_dump($e));
    }

     
    Friday, January 29, 2016 2:49 AM
    Moderator

All replies

  • That's correct. I had some queries that worked on a different server and when I transferred everything to Azure I could only SELECT and UPDATE. The INSERT queries were broken so I think it has something to do with the privileges of the database user I'm using.
    Thursday, January 28, 2016 1:52 PM
  • Which PHP MySQL operations lib you use? As I have a simple test on Azure Web app, and which works fine with "INSERT" query.

    Here is the test code snippet for your information:

    $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    try {
        $stmt = $DBH->prepare("INSERT INTO user (`name`, `age`) VALUES (?, ?)");
        $stmt->execute(array('somebody',25));
        $affected_rows = $stmt->rowCount();
        var_dump($affected_rows);
    }
    catch(Exception $e) {
        die(var_dump($e));
    }

     
    Friday, January 29, 2016 2:49 AM
    Moderator