I got the following error for PHP after recent portupgrade:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/20090626/memcache.so' - /usr/local/lib/php/20090626/memcache.so: Undefined symbol "php_session_create_id" in Unknown on line 0
to fix this all you need to do is reinstall pecl-memcache, like this:
cd/usr/ports/databases/pecl-memcache
make deinstall
makeinstall clean
If you need to add functions to an Object on the fly in PHP, here is a possible solution:
class MyClass
{publicfunction __call($m,$a){if(isset($this->$m)){$func=$this->$m;$func();}}}$test=new MyClass();$test->runtimeAddedFunction=function(){echo"It Works !";};$test->runtimeAddedFunction();
Sometimes during PHP unit testing You'll need to redefine a function, and then - later - restore it to it's original state. One way to do that with Runkit ... Let's say that we don't want to get "Cannot modify header information - headers already sent by" error messages when testing a code which uses setcookie php command. We can use the following trick:
use it with caution, and do not forget to RESTORE the function - or it may surprise you !
I have been struggling with setting up runkit with PHP 5.3 under Windows 7, and found out that there is no DLL released for that version, and PHP will not work with pre-compiled DLL's you can found on the net, so I made my own dll which works. Just wanted to share it in hope that it will help others as well.
I like drupal's db_query solution, it's simple, it's secure and easy to implement. If you want to use it outside of the Drupal framework, here is a stand alone code for mysql...
function _db_query_callback($match,$init=FALSE){
static $args=NULL;if($init){$args=$match;return;}switch($match[1]){case'%d':// We must use type casting to int to convert FALSE/NULL/(TRUE?)return(int)array_shift($args);// We don't need db_escape_string as numbers are db-safecase'%s':returnmysql_escape_string(array_shift($args));case'%%':return'%';case'%f':return(float)array_shift($args);case'%b':// binary datareturn"'".mysql_real_escape_string(array_shift($args))."'";}}function db_query($query){$args=func_get_args();array_shift($args);if(isset($args[0]) and is_array($args[0])){// 'All arguments in one array' syntax$args=$args[0];}
_db_query_callback($args,TRUE);$query=preg_replace_callback('/(%d|%s|%%|%f|%b)/','_db_query_callback',$query);returnmysql_query($query);}
Firts you need to connect to the database, then you can use the function like this:
$conn=mysql_connect([HOST],[USERNAME],[PASSWORD]) or die(mysql_error());;mysql_select_db([DB_NAME]) or die(mysql_error());
db_query('INSERT INTO `demo_table` (name,address,number) VALUES("%s","%s",%d)','name','address',123);