Skip to content

Instantly share code, notes, and snippets.

@arturom
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturom/f22fd278a7494573b7b1 to your computer and use it in GitHub Desktop.
Save arturom/f22fd278a7494573b7b1 to your computer and use it in GitHub Desktop.
Get raw mysqli from Cake's default config
<?php
// get the raw mysql object
$dataSource = ConnectionManager::getDataSource('default');
$mysqli = $dataSource->connection;
// dump the config
var_dump($dataSource->config);
// query the database
$query = 'select * from am_assets';
$result = $mysqli->query($query);
echo $result->num_rows, 'rows found', PHP_EOL;
// iterate through the results row by row
$i = 0;
while($row = $result->fetch_assoc()) {
echo $i++, "\t", $row['id'], PHP_EOL;
}
$result->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment