Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pquery
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
pquery
Commits
9468e05b
Commit
9468e05b
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Removed config file and checnged method name.
parent
59872815
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pquery.php
+8
-3
8 additions, 3 deletions
pquery.php
pquery.sql.php
+56
-7
56 additions, 7 deletions
pquery.sql.php
with
64 additions
and
10 deletions
pquery.php
+
8
−
3
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").'
,
...
...
This diff is collapsed.
Click to expand it.
pquery.sql.php
+
56
−
7
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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment