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