Is it possible to execute a MySQL query using Phing and set the value as a property?

I am new to Phing.

I would like to query the value in the MySQL database table and set the value as a property so that I can display it well on the screen.

I see that there is a PDOSQLExecTask that will allow me to run some SQL, but I don’t see how to set the return value to the property?

The query I want to run is: SELECT MAX ( change_number ) FROM changelog ;

I would like it to enter the property:

Can anyone shed some light?

Thank you, Chris

+4
source share
2 answers

I have access to MySQL on the command line, I went with the following solution. I am sure this is not the best, if anyone can improve it, please do it!

  <!-- What the latest delta that been applied to this deployment? --> <exec command="${progs.mysql} -h${db.host} -u${db.user} -p${db.pass} -e 'USE ${db.main_db}; SELECT MAX(`change_number`) FROM `changelog`;'" dir="." checkreturn="false" passthru="false" outputProperty="latest_version_output" /> <php expression="preg_replace('/[^0-9]|\r|\n/si', '', '${latest_version_output}');" returnProperty="latest_version_applied" /> <echo msg="Latest delta applied was: ${latest_version_applied}" /> 
+2
source

PDOSQLExecTask comes with two default formatters that send their output to a file. To change this, you probably have to implement your own formatter. On the other hand, the task appears to be reading its SQL commands from a separate file using SQL commands, rather than an assembly file.

So, in general, it seems to me that you better write your own task, perhaps using some code from the PDOSQLExecTask implementation, but with your own command input and the result of the result. If you do not call the mysql binary command line, this is an alternative for you, in which case you can end this call to redirect your output to the property using the outputProperty attribute in ExecTask .

+1
source

All Articles