求问..还是上次拆框架那个事,需要连接sae的数据库,真心没自己设过数据库阿.狂汗.
sae那里就给了这个sae.class.php类, 该肿么用?...............定义数据显示是要另立一个数据com文件呢?还是就写在这个类里?
拆框架真心太悲剧乐, mvc结构,入口文件->数据com层->mod层->pageletes层->表现层->modul层,一层套一层, 我全部给include到入口文件里了,这样写对不对?感觉很绝望. 不知道该进继续拆好,还是退一步重新使用框架好.
sae mysql class
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();
?>
------解决方案--------------------
再来一个...嘿嘿
php codearrsql[] = $sql; $result = $this->conn->getdata($sql); if( $this->conn->errno() )sperror({$sql}
执行错误: . $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}
执行错误: . $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; }}