Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Inserting Data into Table Re: Inserting Data into Table

#141245
Alen
Participant

You should use PDO to connect.

$config = array(‘user’=>’USERNAME’,’pass’=>’PASSWORD’);
try{
$connect = new PDO(‘mysql:host=HOST;dbname=DBNAME’, $config, $config);
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
echo ‘Error’ . $e->getMessage() . ‘
‘;
}
// Query
$results = $connect->query(‘SELECT `B`,`C` FROM `revision` ORDER BY `C` ASC’);

// Pass variable
$views = $connect->query(‘SELECT `C`,`E` FROM `revision` WHERE `C` =’ . $connect->quote($term));

You db query should be within foreach loop, since it needs to loop over all items and store each in the database. Or like @traq said (see below) pass the whole array. (code not tested)

$data = array(‘Cool Title’ => ‘http://#’);
$connect->query(‘INSERT INTO `read` (`title`, `url`) VALUES ($connect->quote($data))’);