Welcome Guest, Not a member yet? Register   Sign In
how to post restfull api to database via codeigniter with explode function?
#1

[url=https://stackoverflow.com/posts/63764218/timeline][/url]

rest api request, type:post, request body:
Code:
{"data":"albert amstrong,18838327"}
If you see, i want to separate json object by "," and post to columns in my database...
my database name is data
how to make it as below.....
Code:
-----------------------------------
|id   | name           | number   |
-----------------------------------
|  1  |albert amstrong | 18838327 |
|     |                |          |
|     |                |          |
|     |                |          |
my php code
Code:
public function index_post()
{
        $data = $this->post('data');
        $data = json_decode($data);
        $sth=$this->db->prepare('INSERT INTO kontak SET name=?, number=?');
        $sth->execute(array_map('trim', explode(',', $data->data)));
}          
error message:
Code:
    <h4>An uncaught Exception was encountered</h4>

<p>Type: Error</p>
<p>Message: Call to undefined method CI_DB_mysqli_driver::prepare()</p>
<p>Filename: /home/dokdafta/domains/donkeys.xyz/public_html/wa/application/controllers/api/Okaja.php</p>
<p>Line Number: 42</p>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB