mysql_insert_array是致命错误

时间:2012-09-13 19:31:03

标签: php

我正在尝试将下面数组的内容插入到我提供的字段中的mysql表中。但我得到了致命的错误:调用未定义的函数mysql_insert_array();     任何想法?

  <?php

 // Open database here
 $connect = mysql_connect("xxxxx", "xxxx", "xxxx") or         die('Couldn\'t connect to MySQL Server: ' . mysql_error());
    mysql_select_db("xxxx", $connect ) or die('Couldn\'t Select the database: ' . mysql_error( $connect ));
    // Let's pretend these values were passed by a form
   $_POST['name'] = "Bob Marley";
   $_POST['country'] = "Jamaica";
   $_POST['music'] = "Reggae";
  $_POST['submit'] = "Submit";

  // Insert all the values of $_POST into the database table `artists`, except
  // for $_POST['submit'].  Remember, field names are determined by array keys!
  $result = mysql_insert_array("artists", $_POST, "submit");

  // Results
    if( $result['mysql_error'] ) {
    echo "Query Failed: " . $result['mysql_error'];
      } else {
    echo "Query Succeeded! <br />";
    echo "<pre>";
    print_r($result);
     echo "</pre>";
    }

   // Close database

     ?>

1 个答案:

答案 0 :(得分:7)

mysql_insert_array不是PHP函数,因此无法调用。

您应该使用mysql_query代替插入数组。或者,您应该使用mysql_pdomysqli库,因为mysql_*函数已弃用。