Ask me to write this DB class, where wrong, plug in the data

Source: Internet
Author: User
 hostname = $hostname; $this->username = $username; $this->password = $password; $this->select_db = $select _db;$ This->con = mysql_connect ($this->hostname, $this->username, $this->password); if (! $this->con) {$this- >error = Die (' Could not Connect: '. mysql_error);} else{mysql_select_db ($this->select_db, $this->con);}} Public Function __destruct () {//exit End Connection Mysql_close ($this->con);} Public Function Insert ($table, $body) {//Insert an array in table $line1 = Implode (', ', $body); $line 2 = Implode (', ', Array_keys ($ echo $sql = "INSERT into $table ($line 2) VALUES ($line 1)"; $result = mysql_query ($sql, $this->con); if (! $result) { echo $this->error;echo ' 111 ';}} Public Function Update ($table, $body) {}public function read ($table, $keyword) {}public function Delete ($table, $keyword) {}public function GetLastError () {//returns the last error message return $this->error;}}? >

The home page is called
 
  ' AA ', ' bb ' = ' dd '); $DB->insert (' 1234 ', $line 1);? >

echo $sql statement is insert INTO 1234 (AA,BB) VALUES (' AA ', ' DD ')


Reply to discussion (solution)

Query $this->con with mysql_error, no error message returned .... I'm crazy now-begging for answers ....

Require (' DB.class.php ');
$DB = new DB (' localhost ', ' root ', ' ', ' dbtest ');
$line 1 = Array (
' AA ' = ' ' AA ',
' BB ' = ' dd '
);
$DB->insert (' 1234 ', $line 1);

Your $line1 array is written in reverse.
The INSERT statement also has a format: INSERT INTO Tb_member set username = "Test", type = 1, Lastlogindt = Now (). Similar to the update style.
You can also look at the database class written by others, I feel very good: http://www.cnblogs.com/hooray/archive/2012/07/21/2603017.html

Your $line1 array is written in reverse.
The INSERT statement also has a format: INSERT INTO Tb_member set username = "Test", type = 1, Lastlogindt = Now (). Similar to the update style.
You can also look at the database class written by others, I feel very good: http://www.cnblogs.com/hooray/archive/201 ... Actually did not write anti--three floor pointed out ... is a question of little symbols .....

Require (' DB.class.php ');
$DB = new DB (' localhost ', ' root ', ' ', ' dbtest ');
$line 1 = Array (
' AA ' = ' ' AA ',
' BB ' = ' dd '
);
$DB->insert (' 1234 ', $li ... Alas--There are always weird little mistakes ...

  • 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.