现在的位置: 首页 > 综合 > 正文

SAE上连接MySQL数据库

2017年07月24日 ⁄ 综合 ⁄ 共 438字 ⁄ 字号 评论关闭

 在sae上部署自己的代码后,肯定是需要连接到sae 的数据库的,接下来看看如何实现数据库的连接。sae连接数据库已经被模块化, 只需要使用Saemysql类即可实现。

<?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();
?>

抱歉!评论已关闭.