<i id='EfGWb'><tr id='EfGWb'><dt id='EfGWb'><q id='EfGWb'><span id='EfGWb'><b id='EfGWb'><form id='EfGWb'><ins id='EfGWb'></ins><ul id='EfGWb'></ul><sub id='EfGWb'></sub></form><legend id='EfGWb'></legend><bdo id='EfGWb'><pre id='EfGWb'><center id='EfGWb'></center></pre></bdo></b><th id='EfGWb'></th></span></q></dt></tr></i><div id='EfGWb'><tfoot id='EfGWb'></tfoot><dl id='EfGWb'><fieldset id='EfGWb'></fieldset></dl></div>
    <bdo id='EfGWb'></bdo><ul id='EfGWb'></ul>
        <tfoot id='EfGWb'></tfoot><legend id='EfGWb'><style id='EfGWb'><dir id='EfGWb'><q id='EfGWb'></q></dir></style></legend>

        <small id='EfGWb'></small><noframes id='EfGWb'>

        如何使用 PDO bindParam 将点数据插入 mysql?

        时间:2023-10-04

      1. <small id='0ZRkM'></small><noframes id='0ZRkM'>

            <tbody id='0ZRkM'></tbody>
          <i id='0ZRkM'><tr id='0ZRkM'><dt id='0ZRkM'><q id='0ZRkM'><span id='0ZRkM'><b id='0ZRkM'><form id='0ZRkM'><ins id='0ZRkM'></ins><ul id='0ZRkM'></ul><sub id='0ZRkM'></sub></form><legend id='0ZRkM'></legend><bdo id='0ZRkM'><pre id='0ZRkM'><center id='0ZRkM'></center></pre></bdo></b><th id='0ZRkM'></th></span></q></dt></tr></i><div id='0ZRkM'><tfoot id='0ZRkM'></tfoot><dl id='0ZRkM'><fieldset id='0ZRkM'></fieldset></dl></div>
          <legend id='0ZRkM'><style id='0ZRkM'><dir id='0ZRkM'><q id='0ZRkM'></q></dir></style></legend>

              <bdo id='0ZRkM'></bdo><ul id='0ZRkM'></ul>
                <tfoot id='0ZRkM'></tfoot>

                  本文介绍了如何使用 PDO bindParam 将点数据插入 mysql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  详情

                  我想利用 mysql 的空间扩展,所以我尝试使用 bindParam 将经度和纬度存储在数据类型为 POINT 的 mysql 表中.不幸的是,我不断收到错误 SQLSTATE[23000]:违反完整性约束:1048 列位置"不能为空.

                  I'd like to make use of mysql's spatial extension, so I am trying to store longitude and latitude in a mysql table of datatype POINT using bindParam. Unfortunately, I keep getting the error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'location' cannot be null.

                  我已经检查过经度和纬度是否有值.所以问题必须出在我的代码上,但我看不出我做错了什么.

                  I've checked that longitude and latitude have values. So the problem has to be with my code, but I cannot see what I am doing wrong.

                  这是我正在使用的代码.

                  Here is the code I am using.

                  $location=$latitude." ".$longitude;
                  $sql = "INSERT INTO my_geodata SET location = PointFromText('POINT(:location)')";
                        //INSERT INTO my_geodata SET location = PointFromText('POINT(-41 12)');    
                  
                  try 
                  {
                      $stmt = $dbh->prepare($sql);            
                      $stmt->bindParam(':location', $location, PDO::PARAM_STR);           
                      $stmt->execute();   
                      $dbh = null;
                  }
                  
                  catch(PDOException $e)
                  {               
                      echo $error=$e->getMessage();
                  }
                  

                  问题

                  我做错了什么?如何使用 PDO 和 bindParam 将经度和纬度插入到 mysql 表(使用 POINT 数据类型)中?

                  What am I doing wrong? How can I insert longitude and latitude into a mysql table (that uses POINT datatype) with PDO and bindParam?

                  变化

                  根据 AgreeOrNot 的回答,实现这一目标的一种稍微不同的方法是

                  Based on AgreeOrNot's answer, a slightly different way to achieve this is

                  $location = 'POINT(' . $latitude . " " . $longitude . ')';    
                  $sql = "INSERT INTO my_geodata (location) VALUES (PointFromText(:location))";
                  

                  推荐答案

                  请注意,参数化查询不是(简单的)字符串替换.在您的代码中,您的查询参数被放在一个字符串文字中,该文字将保持不变.

                  Note that parameterizing queries is not (simple) string replacement. In your code your query parameter is put in a string literal which will be kept untouched.

                  试试这个:

                  $location = 'POINT(' . $latitude . " " . $longitude . ')';
                  $sql = "INSERT INTO my_geodata SET location = PointFromText(:location)";
                  

                  这篇关于如何使用 PDO bindParam 将点数据插入 mysql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP PDO bindParam/bindValue 多次 下一篇:pdo 直接将图像插入数据库 - 始终插入 BLOB - 0B

                  相关文章

                  最新文章

                  <tfoot id='ILZIE'></tfoot>
                  • <bdo id='ILZIE'></bdo><ul id='ILZIE'></ul>
                • <small id='ILZIE'></small><noframes id='ILZIE'>

                    <i id='ILZIE'><tr id='ILZIE'><dt id='ILZIE'><q id='ILZIE'><span id='ILZIE'><b id='ILZIE'><form id='ILZIE'><ins id='ILZIE'></ins><ul id='ILZIE'></ul><sub id='ILZIE'></sub></form><legend id='ILZIE'></legend><bdo id='ILZIE'><pre id='ILZIE'><center id='ILZIE'></center></pre></bdo></b><th id='ILZIE'></th></span></q></dt></tr></i><div id='ILZIE'><tfoot id='ILZIE'></tfoot><dl id='ILZIE'><fieldset id='ILZIE'></fieldset></dl></div>

                      <legend id='ILZIE'><style id='ILZIE'><dir id='ILZIE'><q id='ILZIE'></q></dir></style></legend>