0

我想在我的 Phing build.xml中执行以下操作:

<if>
    <not>
        <dbexists dsn="mysql:host=${database.host}" username="${database.username}" password="${database.password}" database="${database.name}"/>
    </not>
    <then>
        <pdosqlexec url="mysql:host=${database.host}" userid="${database.username}" password="${database.password}">
            CREATE DATABASE ${database.name};
        </pdosqlexec>        
        <pdosqlexec url="mysql:host=${database.host};dbname=${database.name}" userid="${database.username}" password="${database.password}">
            <transaction src="create-database-schema.sql"/>
        </pdosqlexec>
    </then>
</if>

不幸的是,我想不出任何可能的方式。dbexists任务显然不存在,也无法创建自定义条件

唯一剩下的可能性是创建一个自定义任务(在 PHP 中)检查数据库是否存在并返回“是”或“否”,可以将其分配到属性中并在 Phing 条件下使用。问题是,我不知道这是否可能;我在文档中看不到任何关于从自定义任务中分配属性的内容,Google 也没有提供帮助。

有没有人有任何想法?

4

1 回答 1

1

我认为您应该能够为此使用<trycatch>任务。

<trycatch property="error">
    <try>
        <pdosqlexec url="mysql:host=${host}" userid="${username}" password="${pw}">
            CREATE DATABASE ${database.name};
        </pdosqlexec>
    </try>
    <catch>
        <echo message="${error}" />
    </catch>
</trycatch>
于 2012-11-14T23:31:43.367 回答