I have one issue in zend framework got stuck due to this error
I developed Rest API but POST urls not working
500: Internal Server Error
but all get urls are working
When i debug all code its showing me error in AbstractTableGateway.php at line no 290 in executeInsert function
$result = $statement->execute();
full function code
protected function executeInsert(Insert $insert)
{
$insertState = $insert->getRawState();
if ($insertState['table'] != $this->table) {
throw new Exception\RuntimeException('The table name of the provided Insert object must match that of the table');
}
// apply preInsert features
$this->featureSet->apply('preInsert', array($insert));
$statement = $this->sql->prepareStatementForSqlObject($insert);
$result = $statement->execute();
$this->lastInsertValue = $this->adapter->getDriver()->getConnection()->getLastGeneratedValue();
// apply postInsert features
$this->featureSet->apply('postInsert', array($statement, $result));
return $result->getAffectedRows();
}
After this line code not working means its showing above error
Related
I am trying to learn how to access soap web services via PHP. I can get a list of functions available. I cannot get a return from a SoapClient function. My code is as follows:
<?php
date_default_timezone_set('America/Chicago');
$fcs = 'fcs is initialized';
$url = 'url is initialized';
$res = 'res is initialized';
$url = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL';
$param = array('ZIP' => '72685');
try {
$client = new SoapClient($url);
$fcs = $client->__getFunctions();
$res = $client->GetCityForecastByZIP($param);
} catch (Exception $e) {
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
echo '<br> url = '.$url;
echo '<br> fcs = '.$fcs;
echo '<br> res = '.$res.'<br>';
?>
I have tried about 6 Soap testing URLs that google can find. Some (http://www.webservicex.com/globalweather.asmx?wsdl) of them have evolved into something else. The one I tried the most (http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL) did seem to be having the same trouble I was in it's web page implementation, http://wsf.cdyne.com/WeatherWS/Weather.asmx.
the Exception Error! is
"Server was unable to process request. ---> A network-related or
instance-specific error occurred while establishing a connection to
SQL Server."
To repeat my results,
1) the Soap client object creation seems to work w/o error.
2) __getFunctions seems to work w/o error.
3) trying to get a result from any of the functions produces the error shown above.
Questions:
1) Is there any error in my code that would cause it not to work?
2) What is a good working Soap Web Service URL sandbox?
It looks like its the weather service. To rule out your code go to http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP
Add your ZIP into the Zip box and hit 'Invoke' and you will get an SQL error. So I would say its safe to assume its not your code and its the server.
I am executing sql server stored procedures, and in output i am getting two things result and message when i execute it from Sql Server management studio. But i don't know how do i get that message in zend framework 2 when i am executing the stored procedure?
class myController{
public function indexAction() {
$getResource = $this->fetchTransStatus('123');
$obj = sqlsrv_fetch_array($getResource, SQLSRV_FETCH_ASSOC);
// $obj will give the result coming from database,
// but i am not getting the message coming from stored procedure
// which i it is sending through RAISERROR
}
public function fetchTransStatus($data = null)
{
$procedure = 'procedure_name';
$params = " #param1 = $data, #param2 = 1";
$stmt = $this->tableGateway->getAdapter()->createStatement();
$stmt->prepare("EXEC $procedure $params");
$result = $stmt->execute();
return $result->getResource();
}
}
How will i get the RAISERROR message coming from stored procedure in zend framework 2?
I'm having problems accessing my PHP backend from AngularJS.
I have followed:
http://coenraets.org/blog/2012/02/sample-application-with-angular-js/
Routing with AngularJS and Slim PHP
Some other's too but those are similar. I've tackled the problem for a few days now and still can't get it working.
First way to call my php script
app.controller('PhoneDetailCtrl',function($scope, $modal, $resource) {
var request_Id = 1;
var Request = $resource('http://mobiiltelefonid24.ee/api/kasutatud_telefonid/'+request_Id);
$scope.request = Request.get();} //this way I get code 200 but 119 empty chars.. So I figure routing should be correct?
Second way I tried
app.controller('PhoneDetailCtrl',function($scope, $modal, Service) {
$scope.request = Service.get({id:1});} //this gives me code 200 but 119 empty chars...
app.service('Service', function ($resource) {
return $resource('api/kasutatud_telefonid/:id', {}, {
update: {method:'PUT'}
});});
PHP code (using mysql db)
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/', 'getPopularPhones');
$app->get('/uued_telefonid','getNewPhones');
$app->get('/kasutatud_telefonid','getUsedPhones');
$app->get('/uued_telefonid/:id', 'getPhoneDesc');
$app->get('/kasutatud_telefonid/:id', 'getPhoneDesc');
$app->run();
/*Other get methods are exactly the same but with different name*/
function getPhoneDesc($id) {
$sql = "SELECT * FROM Phone";
try {
$db = getConnection();
$stmt = $db->query($sql);
$wines = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($wines);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
getConnection() is implemented as shown in wine app tutorial. There is one row in db that has 21 colums so it should return something. Also tried to pass string $wine="teststring" but that also arrived as jibbrjabbre.
Is routing wrong or is there problems with querying from db? (I can query just fine from phpMyAdmin). Out of ideas...
Solved! Slim was falsely configured and meekroDB worked just fine (Thanks mainguy). On top of that there were some issues on webhosts side.
I am getting a fatal php error: "Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /facebook-php-sdk/src/base_facebook.php on line 1340", when making an api call on posts that have been deleted on facebook. i want to be able to delete the post from my database if the post has been deleted from facebook and also remove this fatal error. my api call is in a while loop to return the top posts (ranked on comments, shares and likes). i need to check for the existence of the post before returning the post and delete it from database if removed from facebook.
$get_content_db_info = mysqli_query($dbc , "SELECT * FROM `content`");
echo '<table id="leaugeTable"><thead><tr><th>Name</th><th>Post ID</th><th>Facebook ID</th><th>Score</th></tr></thead><tbody>';
while($row = mysqli_fetch_array($get_content_db_info)){
// then your for loop
$fbApiGetPosts = $facebook->api('/'.$row["fb_id"].'_'.$row["post_id"]);
$fbApiGetShares = $fbApiGetPosts["shares"];
$shareCount = $fbApiGetShares["count"];
$fbApiGetLikes = $facebook->api('/'.$row["post_id"].'/likes');
$countLikes = $fbApiGetLikes["data"];
$likesResult = count($countLikes);
$fbApiGetComments = $facebook->api('/'.$row["post_id"].'/comments');
$countComments = $fbApiGetComments["data"];
$cc = count($countComments);
$score = $likesResult + $shareCount * 2 + $cc * 3;
echo '<tr><td>'.$row["first_name"].' '.$row["last_name"].'</td><td>'.$row["post_id"].'</td><td>'.$row["fb_id"].'</td><td class = "sortCol">'.$score.'</td></tr>';
}
this is my first facebook project and dont know how to go about this.
If the post has been deleted from facebook, you'll see the Fatal error: Uncaught GraphMethodException: Unsupported get request. error. What you can do is:
while($row = mysqli_fetch_array($get_content_db_info)){
try {
// your original while code
} catch ( Exception $e ) {
// error from facebook, post is likely to be deleted
if ( $ex->getMessage() === 'Unsupported get request.' ) {
// delete post from database
}
}
}
The try...catch statement will catch any errors, including Unsupported get request., where you can then delete the post from the database, without affecting the rest of the flow.
Basically I am building a MVC app. In the Model, dbFunctions.php is this code:
<?php
require("config.php");
require("dbconnection.php");
class dbFunctions
{
// setting up the object to connect to the Database
function __construct()
{
$dbConnect = new dbConnection();
}
public function insertPortfolioAdminData($value='')
{
# code...
}
public function login($value='')
{
# code...
}
public function logout($value='')
{
# code...
}
public function dbStoreContactForm($value='')
{
# code...
}
// returns a query with a collection of database objects for the portfolio
public function fetchAllPortfolioItems()
{
$fetchAllPortfolioItemsReturnQry = mysql_query("SELECT description FROM PortfolioItems") or die ('Error: '.mysql_error ());
if($fetchAllPortfolioItemsReturnQry){
return $fetchAllPortfolioItemsReturnQry;
}
}
public function fetchSinglePortfolioItems($primaryKey='')
{
# code...
}
}
?>
dbConnection.php
<?php
require("config.php");
class dbConnection {
private $databaseConnection;
public function dbConnection(){
$databaseConnection = mysql_connect(dbHostName,dbUserName,dbPassword) or die(mysql_error());
mysql_select_db(dbDatabaseName) or die(mysql_error());
}
public function closeConnection(){
mysql_close($databaseConnection);
}
}
?>
The controller:
<?php
// Calling the class to do the work on database
require("./model/dbfunctions.php");
$dbMethods = new dbFunctions();
while($row = mysql_fetch_array($dbMethods->fetchAllPortfolioItems()))
{
$pageContent = $row["description"];
}
// calling the template
require("./views/page_12.php");
?>
Here's the error:
Internal Server Error
The server encountered an internal
error or misconfiguration and was
unable to complete your request.
Please contact the server
administrator,
webmaster#mvcportfolio.adambourg.com
and inform them of the time the error
occurred, and anything you might have
done that may have caused the error.
More information about this error may
be available in the server error log.
Additionally, a 404 Not Found error
was encountered while trying to use an
ErrorDocument to handle the request.
Basically I am trying to do all my DB work in the model then through the model pass it to the view to output it.
I see a few problems that may contribute to the error:
1 - You're using require for the "config.php" but you should really be using require_once. There's no need to load it more than once.
// Replace the require('config.php') with:
require_once('config.php');
2 - Are you defining constants in your "config.php"? The dbConnection::dbConnection() function is looking for constants named dbHostName, dbUserName, dbPassword, and dbDatabaseName. Make sure your "config.php" is defining constants.
3 - The while($row = mysql_fetch_array($dbMethods->fetchAllPortfolioItems())) in dbFunctions.php is wrong. The mysql_fetch_array portion of the while is "recalculated" on every iteration which means that it's executed over and over again. If you assign the value of $dbMethods->fetchAllPortfolioItems() to a variable first, the function is only executed once and the while will iterate through the results. Use this instead:
$result = $dbMethods->fetchAllPortfolioItems();
while($row = mysql_fetch_array($result))
{
$pageContent = $row["description"];
}
As per the while documentation:
It tells PHP to execute the nested
statement(s) repeatedly, as long as
the while expression evaluates to
TRUE.
The mysql_fetch_array($dbMethods->fetchAllPortfolioItems()) part of the while you're using will always evaluate to TRUE as long as the query return a row as it's getting called over and over (thus returning the same first row every single time).
The error that's causing the "Internal Server Error" is probably because your script is taking more than the max_execution_time allowed in php.ini.
It's maybe because you're never actually connecting to the database before you query it.
Essentially, you've made a function with the same name as the class for dbConnection instead of using the __construct method.
You will see a very clear error message in your server error log, in apache on linux:
/var/log/apache/error.log
and I would also take a look (if it is not clear from the previews log) at the mysql error log, which is also somewhere under /var/log/...