PHP connection mysql problem novice!!!
This post was last edited by zuoan2008 on 2013-06-25 16:38:28
My login_action.php.
Include ('.. /config/config_db.php ');
Include ('.. /class/db/class_db.php ');
$username = $_post["username"];
$password =$_post["Password"];
echo "Username:". $username. " --"." Password: ". $password."
";
echo "Db_host:". $db _host. " --"." Db_name: ". $db _name." --"." Db_pass: ". $db _pass." --"." Db_dabase: ". $db _dabase;
$mysqldb ==new mysqldb ($db _host, $db _name, $db _pass, $db _dabase);
$sql = "SELECT * from Loginuser where username= '". $username. "'";
$result = $mysqldb->query ($sql);//Query
$rs = $mysqldb->getrows ($result);//Get record set
$num = $mysqldb->getrowsnum ($result);//Get the number of records
if ($num >0) {
If you are logged in
Session_Start ();
$_session[' username ']= $username;
$_session[' password ']= $password;
echo "";
}else{
echo "Login Error";
}
?>
config_db.php
$db _host = ' localhost ';
$db _name = ' root ';
$db _pass = ' 123456 ';
$db _dabase = ' Test ';
$db _ut = ' UTF8 ';
?>
class_db.php
Class MySQLdb
{
var $host;
var $user;
var $passwd;
var $database;
var $conn;
Implementing variable initialization with a constructor function
Connect database operations at the same time
function MySQLdb ($host, $user, $password, $database)
{
$this->host = $host;
$this->user = $user;
$this->passwd = $password;
$this->database = $database;
$this->conn=mysql_connect ($this->host, $this->user, $this->passwd) or Die ("Could don't connect to $this Host ");
mysql_select_db ($this->database, $this->conn) or Die ("Could not switch to database $this->database");
mysql_query ("Set names ' GBK '");
}
This function is used to close the database connection
function Close ()
{
Mysql_close ($this->conn);
}
This function implements the database query operation
function Query ($QUERYSTR)
{
$res =mysql_query ($queryStr, $this->conn) or Die ("Could not Query Database");
return $res;
}
Error message: Fatal Error:call to a member function Query () on a non-object in D:\AppServ\www\jxc\include\action\login_action.php On line 17
That is, the $result inside login_action.php = $mysqldb->query ($sql);//Query
This line
May I ask how the heroes solve? Thank you!
Share to:
------Solution--------------------