本文整理汇总了PHP中Mysql::get_error方法的典型用法代码示例。如果您正苦于以下问题:PHP Mysql::get_error方法的具体用法?PHP Mysql::get_error怎么用?PHP Mysql::get_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mysql
的用法示例。
在下文中一共展示了Mysql::get_error方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showstep
public function showstep()
{
if ($this->step == 0) {
//默认系统显示
include "templates/index.tpl";
}
if ($this->step == 1) {
//第一步安装,首先清空指定目录下的文件
$this->clearcontent('safe', true);
$this->clearcontent('caches', false);
$this->clearcontent('admin_safe_ims/logs', false);
$this->clearcontent('templates/templates_compile/', false);
include "templates/step1.tpl";
}
if ($this->step == 2) {
$host = trim($_POST["dhost"]);
$database = trim($_POST["dname"]);
$user = trim($_POST["duname"]);
$passwd = trim($_POST["dpasswd"]);
$prefix = trim($_POST["dprefix"]);
//往配置文件里写入数据库信息
$conffile = file_get_contents(MSGROOT . "config.simple.php");
$pattern = array("/(cfg\\[\"dbhost\"\\]=)([^;]+);/i", "/(cfg\\[\"dbuser\"\\]=)([^;]+);/i", "/(cfg\\[\"dbpassword\"\\]=)([^;]+);/i", "/(cfg\\[\"dbname\"\\]=)([^;]+);/i", "/(cfg\\[\"prefix\"\\]=)([^;]+);/i");
$replace = array("\$1 " . "\"" . $host . "\";", "\$1 " . "\"" . $user . "\";", "\$1 " . "\"" . $passwd . "\";", "\$1 " . "\"" . $database . "\";", "\$1 " . "\"" . $prefix . "\";");
$conffile = preg_replace($pattern, $replace, $conffile);
//创建数据库
$sql = trim(file_get_contents(MSGROOT . "install/install.sql"));
$sql_arr = explode("Create table ims_", $sql);
array_shift($sql_arr);
require MSGROOT . "include/db.class.php";
$mysql = new Mysql($host, $user, $passwd, $database, $prefix);
foreach ($sql_arr as $sql) {
$sql = "Create table ims_" . $sql;
$mysql->setQuery($sql);
$mysql->query();
}
$error1 = $mysql->get_error();
//获取要创建的用户名和密码
$admin = trim($_POST['uname']);
$name = trim($_POST['trname']);
$upasswd = sha1(trim($_POST['upasswd']));
$createuser = "insert into ims_user(username,password,userleve,nickname) values (\"{$admin}\",\"{$upasswd}\",1,\"{$name}\")";
$mysql->setQuery($createuser);
$mysql->query();
$error2 = $mysql->get_error();
if ($error1 > 0 || $error2 > 0) {
echo "安装过程中似乎哪里出错了,请检查或者手动编辑根目录下的config.simple.php并改名为config.php文件";
} else {
echo "系统安装成功,正在转向管理后台!";
//写入安装锁定文件
file_put_contents(MSGROOT . "install/install.lock", "If you want to reinstall the system,please remove this file!");
//写入新的配置文件
file_put_contents(MSGROOT . "config.php", $conffile);
echo "<script>setTimeout(function(){window.location.href=\"../admin_safe_ims/\";},1500);</script>";
}
}
}
示例2: showui
//获取sql语言,如果返回结果为数字,则是因为必填项不合法
$sql = $msg_ins->getsql();
//如果$sql为整数,则用户输入出现错误,否则,则提交数据库
if (gettype($sql) == "integer") {
$errorcode = $sql;
showui($errorcode);
//goto view;
exit;
} else {
//加载数据库类,并实例化
require_once MSGROOT . "include/db.class.php";
$mysql = new Mysql($sysconf->dbhost, $sysconf->dbuser, $sysconf->dbpassword, $sysconf->dbname, $sysconf->prefix, $sysconf->lang);
$mysql->setQuery($sql);
$mysql->query();
//获取mysql的执行错误代码
$errorcode = $mysql->get_error();
showui($errorcode);
exit;
}
//其它未知错误
$errorcode = 8;
showui($errorcode);
//当检查到错误代码出现时,直接程序直接跳转到这里
//执行结果展示
//PHP5.2以上版本
function showui($errorcode)
{
$cachefile = MSGROOT . "caches/caches_" . $lang . "_" . $errorcode . ".html";
//缓存文件的存放地址
global $userlang, $timer, $sysconf;
//如果系统开启缓存,则直接显示缓存文件