Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Listen, you need to stop using the deprecated <code>mysql_*</code> functions. They will cause you a lot of headache. I suggest you setup mysql to use <code>PDO</code>. Here is an example.</p> <p>Connect to it first and have it throw exceptions for you to handle yourself.</p> <pre><code>try { $pdo = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password); $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo 'ERROR: ' . $e-&gt;getMessage(); } </code></pre> <p>Now run your update.</p> <pre><code>try { $stmt = $pdo-&gt;prepare('INSERT INTO position VALUES(:deviceId, :name, :latitude, :longitude)'); $stmt-&gt;execute(array( ':deviceId' =&gt; $deviceID, ':name' =&gt; $name, ':latitude' =&gt; $latitude, ':longitude' =&gt; $longitude )); // Affected Rows? echo $stmt-&gt;rowCount(); // 1 } catch(PDOException $e) { echo 'Error: ' . $e-&gt;getMessage(); } </code></pre> <p>// Per your question to json_encode</p> <p>After you call the <code>execute()</code> statement the same way (but with a <code>SELECT</code>) you will just need to do this. </p> <pre><code>$results = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC); // This will be an array $json_results = json_encode($results); </code></pre> <p>Later down the line if you want to get it as an object (which I prefer to work with)</p> <pre><code>$results = $stmt-&gt;fetchAll(PDO::FETCH_OBJ); </code></pre> <p>Also if you want to get a single result, use <code>fetch()</code></p> <pre><code>$result = $stmt-&gt;fetch(PDO::FETCH_ASSOC); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload