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);
Related
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.
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');
I am currently getting this error on one of my files:
/var/www/vhosts/httpdocs/generator/index.php on line 6
Line 6 would be resulting in:
echo $results->GetBookCodesResult->BookCodes->BookInfo->ServiceCode;
My code:
<?php
$config['soap_url'] = "http://myservice.com?WSDL";
if(isset($_REQUEST['codes'])) {
$results = request_Data(explode("\n",$_REQUEST['codes']));
echo $results->GetBookCodesResult->BookCodes->BookInfo->ServiceCode;
}
....
What is the best method to have this fixed? Some advice would be appreciated.
your "->BookCodes" sub-property is empty as you can see in your var_dump-output...
this property "BookInfo" just not exist.. maybe no books are found? ;)
I'm working with a COM object that returns a multidimensional VARIANT array (vt_array), and I'm trying to read values from the array.
When I use print_r($mdArray) it displays variant Object.
(variant_get_type($mdArray) returns 8204.)
I tried using foreach ($mdArray as $oneArray) but I get the message:
Warning: Loader::getfields() [loader.getfields]: Can only handle
single dimension variant arrays (this
array has 2) in
C:\Inetpub\wwwroot\root\script\fileloader.php
on line 135 Fatal error: Uncaught
exception 'Exception' with message
'Object of type variant did not create
an Iterator' in
C:\Inetpub\wwwroot\root\script\fileloader.php:135
Stack trace: #0
C:\Inetpub\wwwroot\root\script\fileloader.php(135):
Loader::getfields() #1
C:\Inetpub\wwwroot\root\testloader.php(21):
Loader->getfields() #2 {main} thrown
in
C:\Inetpub\wwwroot\root\script\fileloader.php
on line 135
(The foreach loop is on line 135)
The only information I can get about the array is by using count($mdArray) which returns 8.
If anyone here has any experience reading from multidimensional VARIANT arrays please tell me how this can be done.
Try this to extract array values through "VBScript". Yes, you read that right...
<?php
$com = new COM("MSScriptControl.ScriptControl");
$com->Language = 'VBScript';
$com->AllowUI = false;
$com->AddCode('
Function getArrayVal(arr, indexX, indexY)
getArrayVal = arr(indexX, indexY)
End Function
');
$y1 = 0;
$y2 = 1;
for ($x=0; $x < count($mdArray); $x++) {
echo $com->Run('getArrayVal', $mdArray, $x, $y1) . ": ";
echo $com->Run('getArrayVal', $mdArray, $x, $y2) . "\n";
}
?>
Tested good on a VBScript-created array, which otherwise gave me the exact same issues and errors as you when trying to coerce it to behave like a PHP array. The above method spawned by the unholy union of PHP and VBscript should extract values piece by piece just fine.
To explain $y1 = 0; $y2 = 1;, keep in mind the parameters of the VBScript function are byref, so you can't pass anything in except a variable.
Edit: Added $com->AllowUI = false to shut off any on-screen popups. Otherwise it would freeze the request if a MsgBox() somehow got called from VBScript and no one was at the server terminal to click 'ok'.
This is my first question :).
Im writing a little twitter app in PHP that sends a DMs to all your followers. What im trying to do right now is to get the list of followers. So through twitter api and getting all usernames but for some reason this parsing error appear. Im new to php(but not so much to programming), I actually started learning it yesterday so please be easy on me ;).
Here is the code:
$t= new twitter();
$t->username= $_GET["username"];
$t->password= $_GET["password"];
$fi = $t->followers();
$xml[$page] = new SimpleXMLElement($fi[2]);
$user1count=0;
while(isset($xml[$page]->user[0])){
foreach ($xml[$page]->user as $user) {
$userdet[(string)$user->screen_name]=array( ’screen_name’=> (string)$user->screen_name, ‘location’=>(string)$user->location, ‘description’=>(string)$user-> description, ‘profile_image_url’=> (string)$user-> profile_image_url, ‘url’=>(string)$user-> url, ‘name’=>(string)$user->name );
$user1details[$user1count]= (string)$user->screen_name;
$user1count++;
}
$page++;
$fi=getfilecontents($friendsurl.$username1."xml?page".$page);
if($fi[0]===false){
echo ("Error :".$fi[1]);
$err=new SimpleXMLElement($fi[2]);
echo " ".$err->error." ";
// echo ““;
die();
}
$xml[$page] = new SimpleXMLElement($fi[2]);
}
And the error said:
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php:125 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php(125): SimpleXMLElement->__construct('') #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/scripts/dmsend.php on line 125
Thank you! :)
It looks like $fi[2] is not a valid xml string. I am not 100% familiar with the twitter API, but I would do a var_dump($fi) and evaluate what is begin returned. From there, you should be able to figure out what is happening.