Using database

From EPESI framework documentation
Jump to: navigation, search

To execute any SQL query you can use DB static method Execute:

example: DB::Execute('SELECT * FROM mytable WHERE myfield=5');

While passing any argument to Execute you should use syntax similar to printf to preserve system safety:

example: DB::Execute('SELECT * FROM mytable WHERE field1=%s AND field2=%d',array($field1,$field2));

Moreover, there are functions that simplify some tasks or grant flexibility. Functions you may find most useful are:

	'id I4 AUTO KEY,'.
	'name C(64) NOTNULL,'.
	'user I4 NOT NULL',
	array('constraints'=>', FOREIGN KEY (user) REFERENCES user_login(id)'));

Table creation should be usually placed in <module name>Install.php file, in install() function. Along with table creation you should also add table deletion in the same file within function uninstall(). To drop a table you can use function