PHP connection MySQL to the novice about the problem!

Source: Internet
Author: User
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--------------------
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.