ln 2 fjern " foran insert
$output = '"INSERT INTO ';
ln 37 slettes
$output .= '"';
slet typecast i ln 39 og 40
ln 40
der er lige smuttet et i i mysql_error skal være mysqli_error
tilrettet code hurtigt aftested
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/include/php/db/mysqlconnection.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<?php
/* test tabel
--
-- Database: `test`
--
-- --------------------------------------------------------
--
-- Struktur-dump for tabellen `tbl_wunderstrudel`
--
CREATE TABLE IF NOT EXISTS `tbl_wunderstrudel` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(25) COLLATE utf8_danish_ci NOT NULL,
`lastname` varchar(25) COLLATE utf8_danish_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci AUTO_INCREMENT=2 ;
--
-- Data dump for tabellen `tbl_wunderstrudel`
--
INSERT INTO `tbl_wunderstrudel` (`id`, `firstname`, `lastname`) VALUES
(1, 'Ronny', 'Olsen');
*/
class mysqliclass {
private $connect;
public function __construct($conn) {
$this->connect = $conn;
}
public function mysqlInsert($table, $row = array(), $val = array()) {
$output = 'INSERT INTO '; // " fjernet foran insert
$output .= $table;
$output .= ' (';
for ($i = 0; $i < sizeof($row); $i++) {
if ($i == sizeof($row) - 1) {
$output .= $row[$i];
} else if ($i < sizeof($row)) {
$output .= $row[$i] . ", ";
}
}
$output .= ') ';
$output .= 'VALUES ';
$output .= '(';
for ($k = 0; $k < sizeof($val); $k++) {
if ($k == sizeof($val) - 1) {
$output .= "'";
$output .= $val[$k];
$output .= "'";
} else if ($k < sizeof($val)) {
if ($val[$k] != null) {
$output .= "'";
$output .= $val[$k];
$output .= "'";
$output .= ", ";
} else {
$output .= "'";
$output .= null;
$output .= "'";
$output .= ", ";
}
}
}
$output .= ')';
// $output .= '"'; // skal ikke på
// echo $output;
mysqli_query($this->connect, $output) or die(mysqli_error($this->connect));
}
}
// database navn sendes med som parameter, og der retuneres en connection til denne database
$conn = MySqlIConnOOP("test");
$mc = new mysqliclass($conn);
$mc->mysqlInsert("tbl_WunderStrudel", array("firstname", "lastname"), array("Ronny", "Olsen"));
?>
</body>
</html>