Re: creating mysql functions using php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Right, problem's obvious really:

There's never any need to use "delimiter" in an API call, as
delimiters aren't used - separate calls are made instead. So the
following code works just fine:

$link = mysql_connect('localhost', 'root', 'pass');
mysql_select_db( 'test' );
$ret = mysql_query( 'DROP FUNCTION IF EXISTS `anti_space` ');
if( !$ret ) echo mysql_error($link);
$ret = mysql_query( 'CREATE FUNCTION  `anti_space` (
inString VARCHAR(1000),
replaceThis VARCHAR(1000),
replaceWith VARCHAR(1000)
)
RETURNS VARCHAR(1000)
DETERMINISTIC
BEGIN
DECLARE _outString VARCHAR(1000) DEFAULT TRIM(inString);
DECLARE _length INT DEFAULT LENGTH(_outString);
DECLARE _doneLoop BOOLEAN DEFAULT FALSE;
DECLARE _lengthNext INT DEFAULT 0;

IF ( _length != 0 ) THEN

WHILE (! _doneLoop AND _length != 0 ) DO

SET _outString = REPLACE( _outString, replaceThis, replaceWith );
SET _lengthNext = LENGTH(_outString);
SET _doneLoop = (_lengthNext = _length);
SET _length = _lengthNext;

END WHILE;

END IF;

RETURN _outString;

END', $link );

D'oh. Hope that helps someone.


Andy

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux