Vartan Posted February 21, 2010 Share Posted February 21, 2010 /* connect to MYSQL*/ $sqllink = mysqli_connect($mysql_host, $mysql_user, $mysql_pass); if (!sqllink) { echo "Unable to connec to Database"; exit(); } else {echo "Connection OK<BR>";} /* set char set*/ if (!mysqli_set_charset($sqllink, 'utf8')) { echo "Unable to set database connection encoding."; exit(); } else {echo "Charset OK<BR>";} /* select database */ if (!mysqli_select_db ($sqllink, $mysql_db)) { echo "unable to select database."; exit(); } else {echo "Database Ok<BR>";} $sqltask = 'CREATE TABLE test ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, field1 text ) DEFAULT CHARACTER SET utf8'; if (!mysqli_query($sqllink, $sqltask)) { echo "Error: ".mysqli_error($sqllink); } $character['name'] = "Zek"; $character['age'] = 25; $character = serialize($character); $sqltask = 'INSERT INTO test VALUES($character)'; if (!mysqli_query ($sqllink, $sqltask)) { echo "mysqli_error($sqllink)"; exit(); } echo $sqltask; ?> i get this error Catchable fatal error: Object of class mysqli could not be converted to string in E:\xampp\htdocs\Dark Heresy\char_sheet.php on line 55 could any one clarify how do i pass an array into a Database? thank you -Vartan Link to comment https://forums.phpfreaks.com/topic/192850-problem-storing-array-into-mysql/ Share on other sites More sharing options...
trq Posted February 22, 2010 Share Posted February 22, 2010 Your not storing an array. Your storing a string representing an array (because it has been serialized). Not the approuch I would take, but anyway.... Firstly, variables are not interpolated within single quotes & secondly, string values need to be surrounded by quotes in sql. $sqltask = "INSERT INTO test VALUES('$character')"; Link to comment https://forums.phpfreaks.com/topic/192850-problem-storing-array-into-mysql/#findComment-1015928 Share on other sites More sharing options...
Vartan Posted February 22, 2010 Author Share Posted February 22, 2010 first of all thank you very much for the answer, when you said its not the approuch you would take, if you dont mind could you give me an example of how you would do it? thank you again -Vartan Link to comment https://forums.phpfreaks.com/topic/192850-problem-storing-array-into-mysql/#findComment-1015975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.