0

Here is generated array:

$data = array();
  for($i = 0; $i < 100; $i++){
      $data[] = array(
      'name'        => md5(rand()),
      'active'        => rand(0, 1)?'active':'banned',
      'create_date'    => rand(0, 1)?'now':'2014/12/31 14:51:52',
      'income'        => base64_encode(rand(-9999, 9999)),
      );
  }

And my try to save this data to database:

$columns = implode(", ",array_keys($data));
$escaped_values = array_map('mysql_real_escape_string', array_values($data));
$values  = implode(", ", $escaped_values);
$sql = "INSERT INTO `data`($columns) VALUES ($values)";

But unfortunately it doesn't work, showing this warning: "MYSQL_REAL_ESCAPE_STRING() EXPECTS PARAMETER 1 TO BE STRING, ARRAY GIVEN IN..."

How to solve this?

1 Answer 1

1

You should write it something like that:

'name'        => mysql_real_escape_string(md5(rand())),

and delele:

$escaped_values = array_map('mysql_real_escape_string', array_values($data));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.