Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata
<?php
try
    {
        $db = new PDO('mysql:host=localhost;dbname=DBNAME', 'username', 'password');
    }
    catch(PDOException $exception)
    {
        die("Unable to open database.<br />Error message:<br /><br />$exception.");
    }

echo 'Successfully connected to Database';

// No "'s inside of Query only '
$statement = $db->query("

select * from table
where
	 column = 'field'

");

 $statement->execute();
 $result = $statement->fetchAll(PDO::FETCH_ASSOC);
 print_r($result);

?>

Another Method:

http://stackoverflow.com/questions/14863806/need-to-return-echo-php-pdo-results-from-database

<?php
try
    {
        $db = new PDO('mysql:host=localhost;dbname=asteriskcdrdb', 'freepbx', 'fpbx');
    }
    catch(PDOException $exception)
    {
        die("Unable to open database.<br />Error message:<br /><br />$exception.");
    }
echo 'Successfully connected to Database';

$query = $db->prepare('SELECT uniqueid FROM cdr WHERE id = 16');
$query->execute();

while ($row = $query->fetch(PDO::FETCH_ASSOC))
{
    $uid = $row['uniqueid'];
}
?>
  • No labels