Re: creating mysql functions using php

From: Date: Thu, 09 Oct 2008 17:11:08 +0000
Subject: Re: creating mysql functions using php
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-45510@lists.php.net to get a copy of this message
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

« previous php.db (#45510) next »