nameQuote() ensures that named elements are encapsulated in the correct
delimiters. Quote() ensures that values are encapsulated in the correct delimiters.
This example demonstrates the use of all of these rules.
$db = JFactory::getDBO();
$query = 'SELECT * FROM '
.$db->nameQuote('#__test')
.' WHERE '
.$db->nameQuote('name')
.' = '
.$db->Quote('Some Name');
If we were using a MySQL or MySQLi database driver, $query would equal
the following:
SELECT * FROM 'jos_test' WHERE 'name' = "Some Name";
Getting Results
We could use the query() method and process the resultant resource. However, it is
far easier to use one of the other JDatabase methods, which will get the results from a
query in a number of different formats.
To help explain each of the methods we will use a sample table called #__test. The
table has two fields, id, an auto-increment primary key, and name, a varchar field.
The table below shows the data we will use for demonstration purposes.
id name
1 Foo
2 Bar
Which methods we choose to use is dependent on three things: the data we want, the
format in which we want it, and our personal preference.
Pages:
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78