Funktion in PDO ändern
Dies ist eine Aussage, die in meiner API verwendet wird. Es ist das zweite$result
Variable in der gesamten Funktion unten. Wie kann man es ändern, um PDO zu verwenden?
$result = query("SELECT p.IdPhoto, p.device_token, /*title,*/ p.IdUser FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto='%d'", $IdPhoto) ;
Ganze Funktion
function stream($IdPhoto=0) {
if ($IdPhoto==0) {
//Load Photos
$result = query("SELECT IdPhoto, device_token, /*title,*/ IdUser FROM photos /*p*/ ORDER BY IdPhoto DESC LIMIT 300 ");
} else {
//Want this to be PDO :)
$result = query("SELECT p.IdPhoto, p.device_token, /*title,*/ p.IdUser FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto='%d'", $IdPhoto) ;
}
Funktioniert dieser Code anstelle der zweiten Ergebnisvariablen? Mein Ziel ist es, es in PDO zu ändern, damit es erfolgreicher skaliert werden kann. Bisher noch keine Ausgabe.
$dbh = new PDO('mysql:host=localhost;dbname=pushchat', 'pushchat', 'A very secure password!!!');
$result = $dbh->query("SELECT p.IdPhoto, p.device_token, /*title,*/ p.IdUser FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto='%d'", $IdPhoto) ;
Dies sind meine Datenbankverbindungswerte
'host' => 'localhost',
'dbname' => 'pushchat',
'username' => 'pushchat',
'password' => 'A very secure password!!!',
Aktualisiere PHP-Protokolldatei
[08-Apr-2016 03:39:25 Europe/Berlin] PHP Notice: Undefined index: IdPhoto in /Applications/MAMP/htdocs/Hi2/index.php on line 44
Aktualisiere
Benutzte die PDO-Syntax in einer Testdatei und der Browser gab eine Zeile zurück. Wie kann ich die App dazu bringen, sie jetzt über j son aufzurufen?
<?php
$conn = new PDO('mysql:host=localhost;dbname=pushchat', 'pushchat', 'd]682\#%yI1nb3');
function new_function()
{
echo "hi<br>";
$an_int = 12;
// If this is an integer
if (is_int($an_int))
{
global $conn;
$stmt = $conn->prepare("SELECT IdPhoto, device_token, IdUser FROM photos ORDER BY IdPhoto DESC LIMIT 300 ");
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($result);
$swag_Bag = 'p.device_token';
print_r($swag_Bag);
}
}
new_function();
?>
Aktualisiere
So hat die App das Original @ genanstream
Funktion.
-(void)refreshStream
{
//The "stream" command from the web API
[[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"stream", @"command", nil] onCompletion:^(NSDictionary *json)
{
//got stream
[self showStream:[json objectForKey:@"result"]];
...
}];
}