求问..还是上次拆框架那个事,需要连接SAE的数据库,真心没自己设过数据库阿.狂汗.sae那里就给了这个sae.class.php类, 该肿么用?...............定义数据显示是要另立一个数据COM文件呢?还是就写在这个类里?拆框架真心太悲剧乐, MVC结构,入口文件->数据com层->mod层->pageletes层->表现层->modul层,一层套一层, 我全部给include到入口文件里了,这样写对不对?感觉很绝望. 不知道该进继续拆好,还是退一步重新使用框架好.
 Sae Mysql Class<?php
$mysql = new SaeMysql();
 
$sql = "SELECT * FROM `user` LIMIT 10";
$data = $mysql->getData( $sql );
$name = strip_tags( $_REQUEST['name'] );
$age = intval( $_REQUEST['age'] );
$sql = "INSERT  INTO `user` ( `name` , `age` , `regtime` ) VALUES ( '"  . $mysql->escape( $name ) . "' , '" . intval( $age ) . "' , NOW() ) ";
$mysql->runSql( $sql );
if( $mysql->errno() != 0 )
{
    die( "Error:" . $mysql->errmsg() );
}
 
$mysql->closeDb();
?>

解决方案 »

  1.   

    sae 是跟sina那个平台的?他给你的class 直接引用后实例化 填写自己的帐号密码应该就可以来操作了吧,我没有办法测试,也没有去仔细看过那个sae.框架除非自己很熟悉了,要不然拆起来真是麻烦的,想想看你就是在解剖啊,对人的生理结构不熟悉,万一,
    原本是要切支手指....我找到个连接sae的数据库类,不知道是不是跟你的差不多,不过我没办法测试只能让你自己看看老,我看了看代码跟我们平时写的没啥区别...
    <?php  
    //设置页面编码  
    header("Content-Type:text/html;charset=utf-8");   
    /** 
     * MySql连接类 
     * @author LightingCui 
     * @since Sep 30, 2010 
     */  
    class MySqlConnection{  
        private $link;//链接  
        private $sqlResult;//查询结果  
        private $ResultRow;//游标所指数据行  
        function __construct(){  
            $link = null;  
            $sqlResult = null;  
            $ResultRow = null;  
            //导入配置文件  
            include_once( 'config.php' );  
            //测试数据库连通性  
            $this->link = @mysql_connect(DB_HOST,DB_USER,DB_PWD)   
                    or die ("Unable to connect to the " .  
                            "database server at this time.");  
            //如果连接失败 程序结束。  
            if (!$this->link) exit();  
            //选择数据库  
            mysql_select_db(DB_NAME,$this->link)   
            or die ("Could not select database! ");  
            //设置数据库编码  
            mysql_query("set names utf8",$this->link);  
        }  
        /** 
         * 关闭连接 
         * @return bool -是否执行成功 
         */  
        function close(){  
            if (!isset($this->link)){  
                return mysql_close($this->link);  
            }else{  
                $sqlResult = null;  
                $ResultRow = null;  
                return true;  
            }  
        }  
        /** 
         * 执行SQL语句 
         * @param sql   -SQL语句 
         * @return bool -是否执行成功 
         */  
        function runSql($sql){  
            if (isset($this->link)){  
                $this->sqlResult = mysql_query($sql,$this->link);  
                return $this->sqlResult;  
            }else{  
                $this->ResultRow = null;  
                $this->ResultRow = null;  
                return false;  
            }  
        }  
        /** 
         * 关闭连接 
         * @return bool 游标是否成功指向下一条数据 
         */  
        function nextRow(){  
            if (isset($this->sqlResult)){  
                $this->ResultRow = mysql_fetch_row($this->sqlResult);  
                return $this->ResultRow;  
            }  
            return false;  
              
        }  
        /** 
         * 获取当前游标所指行的某列数据 
         * @param ColNumber 列数(从0开始) 
         * @return var 所指列的数据 
         */  
        function getCol($ColNumber){  
            if (isset($this->ResultRow)){  
                return $this->ResultRow[$ColNumber];  
            }  
            return null;  
        }  
    }  
    ?>
      

  2.   

    再来一个...嘿嘿 
    <?php
    /////////////////////////////////////////////////////////////////
    // SpeedPHP中文PHP框架, Copyright (C) 2008 - 2010 SpeedPHP.com //
    //////////////////////////////////////////////////////////////////**
     * SAE中MySQL数据库的驱动支持 
     *
     * SAE是Sina App Engine(新浪应用引擎)的缩写,SAE是一个分布式web应用开发运行的服务平台,
     * 其不仅仅包含创建、部署web应用的简单交互,更涉及一整套大规模分布式服务的解决方案。
     *
     * db_sae 封装了SAE提供的SaeMysql类的驱动操作。
     */
    class db_sae {
            /**
             * 数据库链接句柄
             */
            public $conn;
            /**
             * 执行的SQL语句记录
             */
            public $arrSql;        /**
             * 按SQL语句获取记录结果,返回数组
             * 
             * @param sql  执行的SQL语句
             */
            public function getArray($sql)
            {
                    $this->arrSql[] = $sql;
                    $result = $this->conn->getData($sql);
                    if( $this->conn->errno() )spError("{$sql}<br />执行错误: " . $this->conn->error());
                    return $result;
            }
            
            /**
             * 返回当前插入记录的主键ID
             */
            public function newinsertid()
            {
                    return $this->conn->lastId();
            }
            
            /**
             * 格式化带limit的SQL语句
             */
            public function setlimit($sql, $limit)
            {
                    return $sql. " LIMIT {$limit}";
            }        /**
             * 执行一个SQL语句
             * 
             * @param sql 需要执行的SQL语句
             */
            public function exec($sql)
            {
                    $this->arrSql[] = $sql;
                    $result = $this->conn->runSql($sql);
                    if( $this->conn->errno() )spError("{$sql}<br />执行错误: " . $this->conn->error());
                    return $result;
            }
            
            /**
             * 返回影响行数
             */
            public function affected_rows()
            {
                    return FALSE; // SAE环境暂时无法获取影响行数
            }        /**
             * 获取数据表结构
             *
             * @param tbl_name  表名称
             */
            public function getTable($tbl_name)
            {
                    return $this->getArray("DESCRIBE {$tbl_name}");
            }        /**
             * 构造函数
             *
             * @param dbConfig  数据库配置
             */
            public function __construct($dbConfig)
            {
                    if(TRUE == SP_DEBUG)sae_set_display_errors(TRUE);
                    $this->conn = new SaeMysql();
                    if( $this->conn->errno() )spError("数据库链接错误 : " . $this->conn->error()); 
                    $this->conn->setCharset("UTF8");
            }
            /**
             * 对特殊字符进行过滤
             *
             * @param value  值
             */
            public function __val_escape($value, $quotes = FALSE) {
                    if(is_null($value))return 'NULL';
                    if(is_bool($value))return $value ? 1 : 0;
                    if(is_int($value))return (int)$value;
                    if(is_float($value))return (float)$value;
                    if(@get_magic_quotes_gpc())$value = stripslashes($value);
                    return '\''.$this->conn->escape($value).'\'';
            }        /**
             * 析构函数
             */
            public function __destruct()
            {
                    @$this->conn->closeDb();
            }
            
            /**
             * getConn 取得Sae MySQL对象
             * 为了更好地使用Sea提供MySQL类,getSeaDB函数将返回Sae MySQL对象供开发者使用
             */
            public function getConn()
            {
                    return $this->conn;
            }
    }
      

  3.   

    理解万岁! 笑眯眯,笑眯眯,刚才去把冷脸的SAE上下左右全翻一遍,终于找出个详细范例来,其实超简单的.我把之前的小范例当成类乐,自己搞混自己