Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pquery
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
pquery
Commits
9468e05b
Commit
9468e05b
authored
Dec 05, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed config file and checnged method name.
parent
59872815
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
10 deletions
+64
-10
pquery.php
pquery.php
+8
-3
pquery.sql.php
pquery.sql.php
+56
-7
No files found.
pquery.php
View file @
9468e05b
...
...
@@ -5,12 +5,17 @@
* @package pQuery
*/
include_once
'pquery.config.php'
;
/**
* Common utility class.
*/
class
pQuery
{
/**
* Name of the utilities folder
*
* @var string
*/
const
UTILS_FOLDER
=
'utils/'
;
/**
* Pattern of the alias created for an extending plugin that has defined an alias.
*
...
...
@@ -153,7 +158,7 @@ class pQuery {
$files
=
func_get_args
();
foreach
(
$files
as
$basename
)
{
$path
=
PQUERY_ROOT
.
pQueryConfig
::
UTILS_FOLDER
.
$basename
.
'.php'
;
$path
=
PQUERY_ROOT
.
self
::
UTILS_FOLDER
.
$basename
.
'.php'
;
if
(
!
file_exists
(
$path
)
)
{
return
self
::
error
(
'Utility "%s" could not be loaded (looked in "%s").'
,
...
...
pquery.sql.php
View file @
9468e05b
...
...
@@ -14,6 +14,13 @@ class pQuerySql extends pQuery implements pQueryExtension {
static
$accepts
=
array
(
'string'
=>
'parse_query'
,
'resource'
);
/**
* The default row fetching type, one of 'assoc', 'object' or 'array'.
*
* @var resource
*/
const
DEFAULT_FETCH_TYPE
=
'assoc'
;
/**
* The MySQL link identifier.
*
...
...
@@ -27,6 +34,14 @@ class pQuerySql extends pQuery implements pQueryExtension {
*/
static
$variable_alias
=
'query'
;
/**
* Database login data, should be an associative array containing
* values for 'host', 'username', 'password' and 'dbname'
*
* @var array
*/
static
$login_data
=
array
();
/**
* The result of the current query.
*
...
...
@@ -91,7 +106,7 @@ class pQuerySql extends pQuery implements pQueryExtension {
* @param array $variables The variables to replace.
* @returns pQuerySql The current query object.
*/
function
set_
plain
(
$variables
)
{
function
set_
unescaped
(
$variables
)
{
return
$this
->
replace_variables
(
$variables
,
false
);
}
...
...
@@ -114,7 +129,6 @@ class pQuerySql extends pQuery implements pQueryExtension {
function
execute
()
{
self
::
assert_connection
();
//debug('query:', $this->query);
$result
=
mysql_query
(
$this
->
query
,
self
::
$link
);
if
(
!
$result
)
...
...
@@ -132,7 +146,7 @@ class pQuerySql extends pQuery implements pQueryExtension {
* @param string $type The format of the result row.
* @returns mixed The fetched row in the requested format.
*/
function
fetch
(
$type
)
{
function
fetch
(
$type
=
self
::
DEFAULT_FETCH_TYPE
)
{
$this
->
assert_execution
();
if
(
!
$this
->
result
)
...
...
@@ -152,7 +166,7 @@ class pQuerySql extends pQuery implements pQueryExtension {
* @param string $type The format of the result rows.
* @returns array The result set.
*/
function
fetch_all
(
$type
)
{
function
fetch_all
(
$type
=
self
::
DEFAULT_FETCH_TYPE
)
{
$results
=
array
();
while
(
(
$row
=
$this
->
fetch
(
$type
))
!==
false
)
{
...
...
@@ -171,6 +185,42 @@ class pQuerySql extends pQuery implements pQueryExtension {
$this
->
executed
||
$this
->
execute
();
}
/**
* Set database server login data.
*
* @param string $host The database server to connect with.
* @param string $username The username to login with on the database server.
* @param string $password The password to login with on the database server.
* @param string $dbname The name of the database to select after connecting to the server.
*/
static
function
set_login_data
(
$host
,
$username
,
$password
,
$dbname
)
{
// Close any existing connection
if
(
self
::
$link
)
{
mysql_close
(
self
::
$link
);
self
::
$link
=
null
;
}
self
::
$login_data
=
array_merge
(
self
::
$login_data
,
compact
(
'host'
,
'username'
,
'password'
,
'dbname'
));
}
/**
* Assert that the database server config has been set.
*/
static
function
assert_login_data_exist
()
{
if
(
!
isset
(
self
::
$login_data
[
'host'
])
)
return
self
::
error
(
'No SQL host specified.'
);
if
(
!
isset
(
self
::
$login_data
[
'username'
])
)
return
self
::
error
(
'No SQL username specified.'
);
if
(
!
isset
(
self
::
$login_data
[
'password'
])
)
return
self
::
error
(
'No SQL password specified.'
);
if
(
!
isset
(
self
::
$login_data
[
'host'
])
)
return
self
::
error
(
'No SQL host specified.'
);
}
/**
* Assert that the MySQL connection is opened.
*
...
...
@@ -181,11 +231,10 @@ class pQuerySql extends pQuery implements pQueryExtension {
if
(
self
::
$link
)
return
;
if
(
!
isset
(
pQueryConfig
::
$sql
)
)
return
self
::
error
(
'Could not connect to database: no MySQL config found.'
);
self
::
assert_login_data_exist
();
// Connect to the database
$c
=
pQueryConfig
::
$sql
;
$c
=
self
::
$login_data
;
$link
=
@
mysql_connect
(
$c
[
'host'
],
$c
[
'username'
],
$c
[
'password'
]);
if
(
$link
===
false
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment