Sunday, October 28, 2012

FreeTDS Output Parameter Not Return to PHP

I had a stored procedure that returned with the output parameter (I found it in the FreeTDS log file) but the variable of the output parameter was blank in PHP. I checked the stored procedure and I found a stupid 'select @foo' selection in the procedure, before the initialization of the output parameter (set @output='bar'). I commented the selection (--select @foo) and now it works like a charm, the value of ouput parameter is available in the output PHP variable. I hope this helps you.

Tuesday, October 16, 2012

Native SQL Query in Doctrine

// get Doctrine_Connection object
$con = Doctrine_Manager::getInstance()->connection();
// execute SQL query, receive Doctrine_Connection_Statement
$st = $con->execute("...............");
// fetch query result
$result = $st->fetchAll();
Or with parameter...
$db = Doctrine_Manager::getInstance()->connection();
$query = $db->prepare("INSERT INTO search_term (term, counter) VALUES (:term, '1') ON DUPLICATE KEY UPDATE counter=counter+1;");
$query->execute(array('term' => $search));


function mb_ucfirst($string, $encoding)
    $strlen = mb_strlen($string, $encoding);
    $firstChar = mb_substr($string, 0, 1, $encoding);
    $then = mb_substr($string, 1, $strlen - 1, $encoding);
    return mb_strtoupper($firstChar, $encoding) . $then;