【问题标题】:Best data access methods for PHP/Codeigniter/jQuery/MySQLPHP/Codeigniter/jQuery/MySQL 的最佳数据访问方法
【发布时间】:2011-04-11 23:17:40
【问题描述】:

我最初是一个 .NET 开发人员,所以我一直习惯于使用 ADO.net 和 LINQ 来实现对网格视图和其他 .net 控件的强类型、轻松的数据访问。在尝试使用 CodeIgniter 和少量 jQuery 学习 PHP 和 MySQL,但我很难可视化我的数据访问方法。

我想为我的网格控件(我非常依赖)使用 PHP 或 jquery 网格。从 MySQL 环境中填充它们的最佳方法是什么?我听说过很多关于使用 JSON 的信息,但我还没有研究过它。我也很确定 CodeIgniter 也可以进行大量数据访问。

我需要采取什么方向?谢谢 Stackoverflow!

【问题讨论】:

    标签: php jquery mysql json data-access


    【解决方案1】:

    echo json_encode($result);

    【讨论】:

      【解决方案2】:

      让我们开始吧:

      普通 PHP

      <?php
        class Report{
                 ….
           public function __construct($city, $sidx, $sord, $_search, $searchField, $searchString, $searchOper){
               //connecting to db, stm, execute query, fetch array from result …..
                  echo json_encode(array("name"=>"Alissa", "phone" => "555-55551", "city" => "Sussex");
                 //or
                  echo json_encode($result);
                  //where result is an associative array, codeigniter can map such objects from ORM results
          }
       }
      
       $report = new Report($_GET['city'], $_GET['sidx'], $_GET['sord'], $_GET['_search'],$_GET['searchField'],$_GET['searchString'],$_GET['searchOper'])
      ?>
      

      jQuery/html端使用jqGrid

      $("#grid").jqGrid({
             url: 'report.php?city=' + c + '&searchString=null&searchField=null&searchOper=null',
             datatype: 'json',
             mtype: 'GET',
             colNames: ['Name', 'Phone', 'City'],
             colModel: [
                      { name:'rows.name',      index: 'name',   search:true, jsonmap: 'name',  width: 30, align: 'left', sortable:true},
                      { phone:'rows.phone',    index: 'phone',               jsonmap: 'phone', width: 50, align: 'left'},
                      { name:'rows.city',      index: 'city',                jsonmap: 'city',  width: 50, align: 'left', sortable: true},
             pager: '#pager',
             rowNum: 8,
             autowidth: true,
             rowList: [8, 16,32,48],
             sortname: 'name',
             sortorder: 'asc',
             viewrecords: false,
             caption: 'Customer',
             jsonReader : {
                            root: "rows",
                            repeatitems: false
                          },
             height: 650,
             width: 800
       });
      

      无论您使用什么 PHP 框架,相信我。我使用 QCubed,有时我会为此编写普通的 PDO 类。

      你可以检查这个: http://www.codeigniter-jquery.com/codeigniter/using-json-in-codeigniter-with-jquery/

      【讨论】:

        【解决方案3】:

        我不太确定您到底在问什么,但这可能会有所帮助: Datamapper

        它使查询变得简单,建立在 codeigniter 的 Active Records 之上

        【讨论】:

          猜你喜欢
          • 2011-07-19
          • 1970-01-01
          • 2010-12-12
          • 2011-02-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-03-18
          相关资源
          最近更新 更多