Error when creating a diagram via jawira/db-draw php - php

I want to create a database diagram using php jawira/db-draw library (https://jawira.github.io/db-draw/index.html) for this.
Without using SQL queries everything works great, but when I want to use a query it displays an error.
Fatal error: Uncaught TypeError: Jawira\DbDraw\DbDraw::__construct(): Argument #1 ($connection) must be of type Doctrine\DBAL\Connection, Doctrine\DBAL\Driver\PDO\Statement given, called in C:\xampp\htdocs\diagram\index.php on line 18 and defined in C:\xampp\htdocs\diagram\vendor\jawira\db-draw\src\DbDraw.php:26 Stack trace: #0 C:\xampp\htdocs\diagram\index.php(18): Jawira\DbDraw\DbDraw->__construct(Object(Doctrine\DBAL\Driver\PDO\Statement)) #1 {main} thrown in C:\xampp\htdocs\diagram\vendor\jawira\db-draw\src\DbDraw.php on line 26
Code below:
require_once __DIR__.'/vendor/autoload.php';
use Doctrine\DBAL\DriverManager;
use Jawira\DbDraw\{DbDraw, Theme};
use Jawira\PlantUmlClient\{Client, Format};
// a. Some logic to retrieve $connection (\Doctrine\DBAL\Connection)
$connectionParams = ['url' => 'mysql://root:#127.0.0.1/baza_testowa',
'driver' => 'pdo_mysql'];
$connection = DriverManager::getConnection($connectionParams);
$sql = 'SELECT * FROM czlowiek';
$stmt = $connection->query($sql);
//b. Generating PlantUML diagram
$dbDiagram = new DbDraw($stmt);
$puml = $dbDiagram->generatePuml(DbDraw::MAXI, Theme::AMIGA);
file_put_contents('database.puml', $puml);
// c. Converting & saving png image
$client = new Client();
$png = $client->generateImage($puml, Format::PNG);
file_put_contents('database.png', $png);
$url = $client->generateUrl($puml, Format::PNG);
echo "<img src='$url'>";
Probably on the line:
$dbDiagram = new DbDraw($stmt);
There is a value written in parentheses. But the documentation is poor, so I don't know exactly what to put there. When I type $connection there it displays a diagram skipping the SQL query.
Please help.

Related

Error on integrating php and google sheets api

I am trying to integrate google sheets api with php so that I can capture html form data and append it to spreadsheet but I am facing a weird error.
Below is the php snippet:
$client = new \Google_Client();
$client->setApplicationName('WEBMONK_QUOTATION_REQUESTS');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig('../credentials.json');
$service = new Google_Service_Sheets($client);
$spreadsheets_id = '1S2LPDl5XmOEx4TQ3cR4yZ4SAALcxXRyxU5nFMU7RW0I';
$range = 'QUOTESHEET';
$sheet_rows = [
strval($datetime),
strval($name),
strval($email),
strval($url),
strval($extras)
];
$body = new Google_Service_Sheets_ValueRange(['values' => [$sheet_rows]]);
$params = ['valueInputOption' => 'RAW'];
$insert = ['insertDataOption' => 'INSERT_ROWS'];
$result = $service->spreadsheets_values->append(
$spreadsheets_id,
$range,
$body,
$params,
$insert
);
Here is the error I am getting:
<br />
<b>Fatal error</b>: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php:291
Stack trace:
#0 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php(291): implode(Array, '&')
#1 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php(190): Google_Service_Resource->createRequestUri('v4/spreadsheets...', Array)
#2 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient-services\src\Google\Service\Sheets\Resource\SpreadsheetsValues.php(64): Google_Service_Resource->call('append', Array, 'Google_Service_...')
#3 C:\xampp\htdocs\webric.org\api\post\insert.php(68): Google_Service_Sheets_Resource_SpreadsheetsValues->append('1S2LPDl5XmOEx4T...', 'QUOTESHEET', Object(Google_Service_Sheets_ValueRange), Array, Array)
#4 {main}
thrown in <b>C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php</b> on line <b>291</b><br />
So far, that I have understood, an implode() function in the Google lib is malfunctioning because of wrong argument type. But I couldn't find anything wrong with my above php code. I have gone through the google sheets and php integration procedures as mentioned here:
PHP with Google Sheets Quickstart
PHP version: 8.0.0,
Google API Client: 2.0
Please tell me where I am going wrong. Thanks in advance.
Just had the same issue after switching to PHP 8.0 (previously working fine with PHP 7.2).
The implode() function in PHP 8.0 has basically the two arguments switched compared to previous versions. I checked out the lastest version of the Resource.php file in the Google library, and you should see that the line 303 reflects those changes already.
I went to my Resource.php file and replaced
$requestUrl .= '?' . implode($queryVars, '&');
with
$requestUrl .= '?' . implode('&', $queryVars);
And it's working again. Hope it helped!
There must be a problem with your values
Verify it by modifying $body to
$body = new Google_Service_Sheets_ValueRange([
"values" => [[1, 2, 3]]
]);
If this request works for you - log [$sheet_rows] to compare the structure and see what is wrong.
PS: Apart from the Quickstart, there is aslo method specific documentation for PHP

Uncaught Error: Call to undefined method DB::execute()

I am using indieteq-php-my-sql-pdo-database-class I found on GitHub
I have created a little page to try and display some database information as seen below, however I receive the error below my test page script below;
My Test Page
<?php
require("Db.class.php");
$db = new Db();
$db->query("SELECT * FROM faction_territories");
if ($db->execute()) {
while ($row = $db->fetch(PDO::FETCH_ASSOC)) {
echo '<tr>
<td>'.$row['territory_id'].'</td>
<td>'.$row['name'].'</td>
<td>'.$row['density'].'</td>
<td>'.$row['sector'].'</td>
<td>'.$row['size'].'</td>
<td>'.$row['respect'].'</td>
<td>'.$row['faction_name'].'</td>
</tr>';
}
echo '</table>';
}
?>
Error
Fatal error: Uncaught Error: Call to undefined method DB::execute() in
/var/www/.../index.php:7 Stack trace: #0 {main} thrown in
/var/www/.../index.php on line 7
Questions
As you'll be able to tell, I'm somewhat new to PHP & PDO. Some nice pointers to where I am going wrong would be nice with any example code please.
The $db->query already execute the query. You just need to iterate over the result.
See here: https://github.com/wickyaswal/indieteq-php-my-sql-pdo-database-class/blob/master/Db.class.php#L189

PHP Connect to Sharepoint using Thybag\SharePointAPI

I have the following code
//$sp = new SharePointAPI('&&', '&&', 'https://&&.net/personal/zzz/_vti_bin/Lists.asmx?WSDL',);
//$sp = new SharePointAPI('&&', '&&', 'https://&&net/personal/zzz/_vti_bin/Lists.asmx?SDL', 'NTLM');
$sp = new SharePointAPI('&&', '&&', 'https://&&net/personal/zzz/_vti_bin/Lists.asmx?WSDL', 'SPONLINE');
$listContents = $sp->read('GetListCollection');
return $listContents;
Depending on which of the "new SharepointAPI" lines I execute, I get a different error.
Using "NTLM", I get the error: -
Uncaught exception 'Exception' with message 'Error'
in /home/shinksyc/public_html/sharepointUpload/src/Thybag/Auth/SoapClientAuth.php:129
Stack trace:
#0 [internal function]: Thybag\Auth\SoapClientAuth->__doRequest('<?xml
version="...', 'https://my.sp.m...', 'http://schemas....', 1, 0)
Using "SPONLINE", I get the error
'Error (Client) looks like we got no XML document'.
I am also slightly confused as to how to find out what the name of the lists may be that I get read.
Any help is much appreciated.
Thanks
Martin
The path to your xml must be local: in clear, log to your sharepoint, go to the url https://mySPsite/subsite/_vti_bin/Lists.asmx?WSDL
Download the XML and place it on your PHP server.
then
$sp = new SharePointAPI($login, $password, $localPathToWSDL, 'NTLM');

net.sf.jasperreports.engine.design.JRValidationException - Query parameter not found

I use JasperServer and PHP JavaBridge to generate PDF reports via JasperServer inside PHP. I get compile error because of missing (unassigned) parameter passed to JRXML compiler
Fatal error: Uncaught [[o:Exception]:
"java.lang.Exception: Invoke failed:
[[c:JasperCompileManager]]->compileReport((o:String)[o:String]).
Cause: net.sf.jasperreports.engine.design.JRValidationException:
**Report design not valid** : 1. **Query parameter not found** : db_field_id VM:
1.6.0_18#http://java.sun.com/" at: #-12
net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:258)
I cant find a way to pass my
$params = new Java("java.util.HashMap");
foreach ($jrxml_params as $key => $jr_param) $params->put($key, $jr_param);
list of params to the compile method nor I can disable this verification by
$japser_props = new JavaClass("net.sf.jasperreports.engine.util.JRProperties");
$japser_props->COMPILER_XML_VALIDATION = false;
Here is what I use to generate PDF (works fine if JRXML file doesn't contain $P{} pamareters and halts otherwise)
$class = new JavaClass("java.lang.Class");
$class->forName("com.mysql.jdbc.Driver");
$driverManager = new JavaClass("java.sql.DriverManager");
$conn = $driverManager->getConnection("jdbc:mysql://localhost:3306/XXX?user=XXX&password=1234");
$compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager");
$report = $compileManager->compileReport(realpath("/www/some.jrxml"));
$params = new Java("java.util.HashMap");
foreach ($jrxml_params as $key => $jr_param) $params->put($key, $jr_param);
$jasperPrint = $fillManager->fillReport($report, $params, $conn);
$exportManager = new JavaClass("net.sf.jasperreports.engine.JasperExportManager");
$outputPath = realpath(".")."/"."output.pdf";
$exportManager->exportReportToPdfFile($jasperPrint, $outputPath);
How do I avoid this error, I know what I need to pass and I don't know a way to do it, can't I just pass params to fillManager?
$japser_props = new JavaClass("net.sf.jasperreports.engine.util.JRProperties");
$japser_props->setProperty('net.sf.jasperreports.compiler.xml.validation',true);
this is the way to set property from PHP but that's not the problem. It turns out everything was fine, I've missed parameter declaration before my MySQL query... Put
<parameter name="db_field_id" class="java.lang.Integer">
in your JRXML before you use it as $P{db_field_id} now it compliles fine and later
$jasperPrint = $fillManager->fillReport($report, $params, $conn);
parameters are assigned at fill time

redbean - nested beans - what's going wrong?

am trying to get a simple nested bean relationship - what am i missing?
i really like redbean's simple ORM syntax and really want to use it, but i can't seem to get it to work for me!
Is there anything else similar to this that's a bit more mature maybe? I want something light and simple to build wordpress plugins with but need to know i can rely on it in the future...
am starting to think about just using ezsql/sqlite but would rather not :/
Thanks for any help...
function p($s){
$s = htmlentities(print_r($s,true));
echo "<pre>$s</pre>";
}
require('rb.php');
R::setup('sqlite:dbfile.sql'); //sqlite\
R::debug(true);
// R::wipe('book');
// R::wipe('author');
$book = R::dispense( 'book' );
$book->title = 'Boost development with RedBeanPHP';
$a = R::dispense('author');
$a->name = "Dave";
$book->author = $a;
list($page1,$page2) = R::dispense('page',2);
$book->pages = array($page1,$page2);
$id = R::store($book);
echo $b = R::load('book',$id);
echo $b->author->name;
I'm getting the following error when trying to store the pages....
Fatal error: Uncaught exception 'RedBean_Exception_Security' with
message 'Invalid Bean: property pages ' in
/Users/sig/Sites/redbean/rb.php:1508 Stack trace: #0
/Users/sig/Sites/redbean/rb.php(1587):
RedBean_OODB->check(Object(RedBean_OODBBean)) #1
/Users/sig/Sites/redbean/rb.php(2523):
RedBean_OODB->store(Object(RedBean_OODBBean)) #2
/Users/sig/Sites/redbean/index.php(30):
RedBean_Facade::store(Object(RedBean_OODBBean)) #3 {main} thrown in
/Users/sig/Sites/redbean/rb.php on line 1508
the problem was that the array needs to have the same name as the objects in it, but with either own or shared prefixed depending on the relationship...
$book->ownPage = array($page1,$page2);

Categories