Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12944509
WithPDOPostgreSQL.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
WithPDOPostgreSQL.php
View Options
<?php
namespace
Keruald\Database\Engines
;
use
LogicException
;
use
PDOException
;
trait
WithPDOPostgreSQL
{
public
function
isExistingTable
(
string
$database
,
string
$table
)
:
bool
{
/** @var \PDO $db */
$db
=
$this
->
getUnderlyingDriver
();
$sql
=
"SELECT EXISTS (
SELECT FROM pg_tables
WHERE schemaname = ?
AND tablename = ?)::int;"
;
$stmt
=
$db
->
prepare
(
$sql
);
$stmt
->
execute
([
$database
,
$table
]);
$result
=
$stmt
->
fetchColumn
();
return
(
bool
)
$result
;
}
public
function
queryScalar
(
string
$query
=
""
)
:
string
{
if
(
$query
===
""
)
{
return
""
;
}
$result
=
$this
->
query
(
$query
);
$row
=
$result
->
fetchRow
();
if
(
$row
!==
null
)
{
foreach
(
$row
as
$value
)
{
return
(
string
)
$value
;
}
}
// No item
throw
new
LogicException
(
"The queryScalar method is intended
to be used with SELECT queries and assimilated"
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Nov 18, 17:18 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3172362
Default Alt Text
WithPDOPostgreSQL.php (1 KB)
Attached To
Mode
rKDB Keruald Database
Attached
Detach File
Event Timeline
Log In to Comment