连不上数据库哪位大神能帮看看
<?phpclass Test_m extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function user_insert($arr)
{
$this->db->insert('user',$arr);
}
function user_update($id,$arr)
{
$this->db->where('uid',$id);
$this->db->update('user',$arr);
}
function user_del($id)
{
$this->db->where('uid',$id);
$this->db->delete('user');
}
function user_select($uname)
{
$this->db->where('uname',$uname);
$this->db->select('*');
$query=$this->db->get('user');
return $query->result();
}
}
?>
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller
{
function index()
{
$this->load->view('login');
}
function checklogin()
{
$this->load->model("test_m");
$user=$this->test_m->user_select($_POST['uname']);
if($user)
{
if($user->upass==$_POST['upass'])
{
echo '密码正确';
$this->load->library('session');
$arr=array('uid'=>$user->uid);
$this->session->set_userdata($arr);
echo '<br />';
echo $this->session->userdata('uid');
}
else
{
echo '密码不正确';
}
}
else
{
echo '用户名不存在';
}
}
function checksession()
{
$this->load->library('session');
if( $this->session->userdata('uid'))
{
echo '已经登录';
}
else
{
echo '没有登录';
}
}
function loginout()
{
$this->load->library('session');
$this->session->unset_userdata('uid');
}
}
<html>
<center><h1>用户登录页面</h1></center>
<form action="/index.php/login/checklogin" method="post">
<center>
<ul style="list-style:none">
<li>用户名</li>
<li><input name="uname" type="text" /></li>
<li>密码</li>
<li><input name="upass" type="password" /></li>
<li><input name="sub" type="submit" value="提交" /></li>
</ul>
</center>
</form>
</html>
A Database Error OccurredUnable to connect to your database server using the provided settings.Filename: C:\AppServ\www\system\database\DB_driver.phpLine Number: 125
将你的数据库配置贴出来 smallerpig 发表于 2015-5-12 14:38
将你的数据库配置贴出来
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'ci';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
http://localhost/phpmyadmin/themes/original/img/s_host.png 服务器: localhost http://localhost/phpmyadmin/themes/original/img/item_ltr.png http://localhost/phpmyadmin/themes/original/img/s_db.png 数据库: ci http://localhost/phpmyadmin/themes/original/img/item_ltr.png http://localhost/phpmyadmin/themes/original/img/s_tbl.png 表 : user
[*]http://localhost/phpmyadmin/themes/original/img/b_browse.png浏览
[*]http://localhost/phpmyadmin/themes/original/img/b_props.png结构
[*]http://localhost/phpmyadmin/themes/original/img/b_sql.pngSQL
[*]http://localhost/phpmyadmin/themes/original/img/b_search.png搜索
[*]http://localhost/phpmyadmin/themes/original/img/b_insrow.png插入
[*]http://localhost/phpmyadmin/themes/original/img/b_tblexport.png导出
[*]http://localhost/phpmyadmin/themes/original/img/b_tblimport.pngImport
[*]http://localhost/phpmyadmin/themes/original/img/b_tblops.png操作
[*]http://localhost/phpmyadmin/themes/original/img/b_empty.png清空
[*]http://localhost/phpmyadmin/themes/original/img/b_deltbl.png删除
显示行 0 - 0 (1 总计, 查询花费 0.0002 秒)
SQL 查询:SELECT *
FROM `user`
LIMIT 0 , 30
[ 编辑 ] [ 解释 SQL ] [ 创建 PHP 代码 ] [ 刷新 ]
Query results operationshttp://localhost/phpmyadmin/themes/original/img/b_print.png打印预览 http://localhost/phpmyadmin/themes/original/img/b_print.png打印预览 (全文显示) http://localhost/phpmyadmin/themes/original/img/b_tblexport.png导出
行,开始行数:
以 水平 水平(旋转标题) 垂直 模式显示,并且在个单元格后重复标题
http://localhost/phpmyadmin/themes/original/img/s_fulltext.pnguidunameupass
http://localhost/phpmyadmin/themes/original/img/b_edit.pnghttp://localhost/phpmyadmin/themes/original/img/b_drop.png111
http://localhost/phpmyadmin/themes/original/img/arrow_ltr.png 全选 / 全部不选 选中项: http://localhost/phpmyadmin/themes/original/img/b_edit.png http://localhost/phpmyadmin/themes/original/img/b_drop.png http://localhost/phpmyadmin/themes/original/img/b_tblexport.png
smallerpig 发表于 2015-5-12 14:38
将你的数据库配置贴出来
help
用phpMyAdmin能连上。。。说实话,我当时也遇到打网页PHP登陆不上mysql数据库,我是修改了密码,在phpMyAdmin修改登陆密码,mysql_connect('localhost','root','12345');这样再登phpMyAdmin就登不上了,然后 我在wamp/apps/phpmyadmin3.2.0.1/config.inc.php 文件里 修改了【'password'】='12345',然后登上phpMyAdmin。
再设置$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '12345';这样子的。。。(纯粹个人胡闹的,仅供阅览) 试试将:$db['default']['dbdriver'] = 'mysql';
换成:
$db['default']['dbdriver'] = 'mysqli'; 你重新配置一份 数据库试试 你确定你在autoload里面配置加载database了? mysql -uroot -p
用这个命令直连一下数据库看看有没有错误,确定是不是密码错误
然后确定端口是3306吧
最后试试把pconnect改成false看看
页:
[1]