/ Published in: PHP
Expand |
Embed | Plain Text
function query($sql){ include("settings.php"); return $result; }
Comments
Subscribe to comments
You need to login to post a comment.
function query($sql){ include("settings.php"); return $result; }
Subscribe to comments
You need to login to post a comment.
Alternatively you could use Pear::DB pear install db
Comment got cut off.
requireonce('DB.php'); $db = &DB::Connect($dburl, array()); if( PEAR::isError($db) ) { die( $db->getMessage() ); }
$res = $db->query($sql); $res->fetchInto( $row, DBFETCHMODEASSOC ); while( $row ) { $rows[] = $row; $res->fetchInto( $row, DBFETCHMODEASSOC ); }
I have a few nicer ways to do this.
function query($sql) { includeonce('./includes/bootstrap.inc'); drupalbootstrap(DRUPALBOOTSTRAPDATABASE); return db_query($sql); }
(Don't worry, Drupal is intelligent enough to not bootstrap itself over and over there.)
Or if you really don't want to use Drupal for your queries:
function query($sql) { static $connection; includeonce('./sites/default/settings.php'); includeonce('./includes/database.mysql.inc'); if (empty($connection)) { $connection = dbconnect($dburl); } return mysql_query($sql, $connection); }