title: PHP Data Type For MySQL POINT Field
body: <p>I created a MySQL table where a field is of type <code>POINT</code> and is used to store lat, lon coordinates (ex: 36.6294654 -93.1725982).</p>
  
  <p>I got an error, with a form submission, and I'm assuming it is due to a mismatched data type.</p>
  
  <pre><code>SQLSTATE[22003]: Numeric value out of range: 1416 Cannot get geometry object from data you send to the GEOMETRY field
  </code></pre>
  
  <p>My understanding is that <code>POINT</code> should have the example's format (I also tried lat, lon).  The problem, I think, is that the space converts the variable into <code>STRING</code>.</p>
  
  <p>Am I missing something, here?</p>
  
  <p>Here is my PHP code to connect to the database and insert the record.</p>
  
  <pre><code>// use google's geocoding service to transform an address into lat/lon coordinates (https://developers.google.com/maps/documentation/geocoding/)
  $json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($street) . ',+' . urlencode($city) . ',+' . urlencode($state) . ',+' . urlencode($zip) . '&amp;key=YOUR_API_KEY');
  $json = json_decode($json, true);
  $latlon = $json['results'][0]['geometry']['location']['lat'] . ' ' . $json['results'][0]['geometry']['location']['lng'];
  try {
      $dbh = new PDO('mysql:host=someserver;port=someport;dbname=somedatabase', 'someusername', 'somepassword', array(PDO::ATTR_PERSISTENT =&gt; true));
      $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $sql = 'INSERT INTO Venues (Name, Street, City, State, Zip, Country, TimeZone, LatLon, Phone, Email, Website, Host, Notes) VALUES (:name, :street, :city, :state, :zip, :country, :timezone, :latlon, :phone, :email, :website, :host, :notes)';
      $stmt = $dbh-&gt;prepare($sql);
      $stmt-&gt;execute(array(":name" =&gt; $name, ":street" =&gt; $street, ":city" =&gt; $city, ":state" =&gt; $state, ":zip" =&gt; $zip, ":country" =&gt; $country, ":timezone" =&gt; $timezone, ":latlon" =&gt; $latlon, ":phone" =&gt; $phone, ":email" =&gt; $email, ":website" =&gt; $website, ":host" =&gt; $host, ":notes" =&gt; $notes));
      if ($stmt-&gt;rowCount() == 1) {
          echo '&lt;p&gt;"' . $name . '" creation succeeded.&lt;/p&gt;';
      } else {
          echo '&lt;p&gt;"' . $name . '" creation failed.&lt;/p&gt;';
      }
      $stmt-&gt;setFetchMode(PDO::FETCH_ASSOC);
      $dbh = null;
  }
  catch(PDOException $e) {
      echo $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>Alternatively, I could just have separate lat and lon fields, but I was wanting to practice with msyql's built-in geometry functionality.</p>
  
  <p>Edit...</p>
  
  <p>Following the advise of <a href="https://stackoverflow.com/a/9560215/953702" title="this answer">this answer</a>, I surrounded <code>$latlon</code> with <code>POINT()</code>.  It didn't change the results, though.</p>
  
  <p>Edit 2...</p>
  
  <p>Here is the table structure, just in case something doesn't look correct.</p>
  
  <pre><code>VenueKey    int(11)
  Name        varchar(255)
  Street      varchar(255)
  City        varchar(255)
  State       varchar(2)
  Zip         varchar(10)
  Country     varchar(2)
  TimeZone    varchar(20)
  LatLon      point
  Phone       varchar(20)
  Email       varchar(255)
  Website     varchar(255)
  Host        varchar(255)
  Notes       text
  </code></pre>