web服务器上的execute()错误,但本地服务器上没有

时间:2016-05-12 07:21:27

标签: php mysql

我的客户网站有一个storelocator,它使用数据库来获取商店的所有信息。这个商店定位器在我的桌面和我的笔记本电脑本地服务器(localhost)上运行良好,但是一旦我将所有内容上传到我的测试站点,商店定位器将无法正常工作。在一个名为locate.php的文件中,我包含一个名为store.php的文件/类,当我转到本地服务器上的locate.php文件时,我只收到通知并不是什么大问题。

enter image description here

当我访问我的网站时,会出现此错误。

enter image description here

locate.php中,我还包含一个名为defines.php的文件,其中包含访问数据库所需的信息(主机,用户名,密码,dbname)。起初我认为它可能是一个GoDaddy问题,但我使用localhost和我的网站IP作为主机,删除并重新上载数据库,似乎没有任何工作。

以下是我在此主题中提到的文件。

locate.php     

include_once("./defines.php");

include_once("./class/store.php");

function vectorLength($x,$y){
    return sqrt(($x*$x)+($y*$y));
}

$R=6378.1;
$count=0;

$total = $_GET['total'];


//$stores[$total];

//$distances[$total];

$lat=$_GET['lat'];
$lng=$_GET['lng'];

$maxdist=0;
$maxid=-1;

//first filter for 100km radius (0.9 degrees on equator = 100km)
$verified_stores = getStores("status=".VERIFIED." AND latitude > '".($lat-0.9)."' AND latitude < '".($lat+0.9)."' AND longitude > '".($lng-0.9)."' AND longitude < '".($lng+0.9)."'",NULL,0,0);

for($i=0;$i<count($verified_stores);$i++){
    $clat = $verified_stores[$i]->latitude;
    $clng = $verified_stores[$i]->longitude;

    $dlat=$lat-$clat;
    $dlng=$lng-$clng;


    //second filter using haversine distance
    $dLat=deg2rad($dlat);
    $dLng=deg2rad($dlng);

    //haversine calculations
    $a = pow(sin($dLat/2),2)+cos(deg2rad($lat)) * cos(deg2rad($clat))*pow(sin($dLng/2),2);

    $c = 2 * asin(sqrt($a));

    $d = $R*$c;

    if($d>$_GET['radius']) continue;

    if($count<$total){
        //keep track of farthest distance
        if($maxdist<$d){
            $maxdist=$d;
            $maxid=$count;
        }

        //insert into list of not full
        $stores[$count]=$verified_stores[$i]->storeID;

        $distances[$count]=$d;
        $count++;
    }
    else{
        //scan distances
        if($d<$maxdist){
            //replace farthest store
            $stores[$maxid]=$verified_stores[$i]->storeID;
            $distances[$maxid]=$d;

            $maxdist=0;

            //find next maxid
            for($j=0;$j<$total;$j++){
                if($maxdist<$distances[$j]){
                    $maxdist=$distances[$j];
                    $maxid=$j;
                }
            }
        }
    }
}

//bubble sort stores

$total=$count;
for($i=0;$i<$total-1;$i++){
    $swapped=false;
    for($j=$i+1;$j<$total;$j++){
        if($distances[$i]>$distances[$j]){
            //swap $i and $j
            $temp=$distances[$i];
            $distances[$i]=$distances[$j];
            $distances[$j]=$temp;

            $temp=$stores[$i];
            $stores[$i]=$stores[$j];
            $stores[$j]=$temp;
            $swapped=true;
        }
    }
}

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo "\n<LOCATIONS>\n";


for($i=0;$i<$total;$i++){
    $store = getStore($stores[$i]);

    $clat=$store->latitude;
    $clng=$store->longitude;

    $dLat=deg2rad($lat-$clat);
    $dLng=deg2rad($lng-$clng);

    //haversine calculations
    $a = pow(sin($dLat/2),2)+cos(deg2rad($lat)) * cos(deg2rad($clat))*pow(sin($dLng/2),2);

    $c = 2 * asin(sqrt($a));

    $d = $R*$c;

    $webpage = $store->webpage;
    if(strlen($webpage)==0) $webpage="<![CDATA[&nbsp;]]>";

    echo "<STORE>\n";
    echo "<DIST>$d</DIST>\n";   
    echo "<NAME><![CDATA[".htmlspecialchars($store->name)."]]></NAME>\n";
    echo "<ADDR>".htmlspecialchars($store->address)."</ADDR>\n";
    echo "<PHONE>".htmlspecialchars($store->phone)."</PHONE>\n";
    echo "<WEBPAGE>$webpage</WEBPAGE>\n";
    echo "<LAT>$clat</LAT>\n";
    echo "<LNG>$clng</LNG>\n";
    echo "</STORE>\n";
}


echo "</LOCATIONS>\n";

?>

store.php

<?php

class Store{
    public $storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated;

    public function __construct($storeID=NULL,$name=NULL,$contact=NULL,$address=NULL,$phone=NULL,$fax=NULL,$email=NULL,$webpage=NULL,$latitude=0,$longitude=0,$status=0,$created=NULL,$updated=NULL){
        $this->storeID=$storeID;
        $this->name=$name;
        $this->contact=$contact;
        $this->address=$address;
        $this->phone=$phone;
        $this->fax=$fax;
        $this->email=$email;
        $this->webpage=$webpage;
        $this->latitude=$latitude;
        $this->longitude=$longitude;
        $this->status=$status;
        //$this->enabled=$enabled;
        $this->created=$created;
        $this->updated=$updated;
    }
    public function toString(){
        $s="StoreID: ".$this->storeID."<br/>";
        $s.="Name: ".$this->name."<br/>";
        $s.="Contact: ".$this->contact."<br/>";
        $s.="Address: ".$this->address."<br/>";
        $s.="Phone: ".$this->phone."<br/>";
        $s.="Fax: ".$this->fax."<br/>";
        $s.="E-mail: ".$this->email."<br/>";
        $s.="Webpage: ".$this->webpage."<br/>";
        $s.="Latitude: ".$this->latitude."<br/>";
        $s.="Longitude: ".$this->longitude."<br/>";
        $s.="Status: ".$this->status."<br/>";
        $s.="Created: ".$this->created."<br/>";
        $s.="Updated: ".$this->updated."<br/>";
        return $s;
    }
}

function restoreStore($id){updateStoreStatus($id,UNVERIFIED);}
function verifyStore($id){updateStoreStatus($id,VERIFIED);}
function unverifyStore($id){updateStoreStatus($id,UNVERIFIED);}
function trashStore($id){updateStoreStatus($id,RECYCLING_BIN);}
function updateStoreStatus($id,$status){
    $db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
    $q=$db->prepare('UPDATE Stores SET status=?, updated=? WHERE storeID=?');
    $date=date("Y-m-d H:i:s");
    $q->bind_param("isi",$status,$date,$id);
    $q->execute();
    $q->close();
    return 1;
}
function emptyStores(){
    $db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
    $q=$db->prepare('DELETE FROM Stores WHERE status='.RECYCLING_BIN);
    $q->execute();
    $q->close();    
    return 1;
}
function deleteStore($id){
    $db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
    $q=$db->prepare('DELETE FROM Stores WHERE storeID=?');
    $q->bind_param("i",$id);
    $q->execute();
    $q->close();    
    return 1;
}

function insertStore($store){
    $db = new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);

    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    $store->created=date("Y-m-d H:i:s");        //overwrite dates
    $store->updated=$store->created;

    if($q = $db->prepare('INSERT INTO Stores (name,contact,address,phone,fax,email,webpage,latitude,longitude,status,created,updated) values (?,?,?,?,?,?,?,?,?,?,?,?)')){
        $q->bind_param("sssssssssiss",
            $store->name,
            $store->contact,
            $store->address,
            $store->phone,
            $store->fax,
            $store->email,
            $store->webpage,
            $store->latitude,
            $store->longitude,
            $store->status,
            $store->created,
            $store->updated);
        $q->execute();
        $q->close();
    }
    else{
        printf($db->errno);
        exit();
    }

    $q=$db->prepare('SELECT storeID FROM Stores WHERE name=? AND created=?');
    $q->bind_param("ss",$store->name,$store->created);
    $q->execute();
    $q->bind_result($sid);
    $q->fetch();
    $q->close();

    if(strlen($sid)>0) return $sid;
    else return ERROR_DEFAULT;
}


//PRE-CONDITION: email, password, billingID, groupID must exist
function updateStore($store){
    $db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);

    //BEGIN ERROR CHECKING -------------------------------

    //END ERROR CHECKING ---------------------------------

    $store->updated=date("Y-m-d H:i:s");        //overwrite dates

    $q=$db->prepare('UPDATE Stores SET name=?, contact=?, address=?, phone=?, fax=?, email=?, webpage=?, latitude=?, longitude=?, status=?, updated=? WHERE storeID=?');
    $q->bind_param("sssssssssisi", $store->name,$store->contact,$store->address,$store->phone,$store->fax,$store->email,$store->webpage,$store->latitude,$store->longitude, $store->status, $store->updated,$store->storeID);
    $q->execute();
    $q->close();

    $q=$db->prepare('SELECT storeID FROM Stores WHERE name=? AND created=?');
    $q->bind_param("ss",$store->username,$store->created);
    $q->execute();
    $q->bind_result($sid);
    $q->fetch();
    $q->close();

    if(strlen($sid)>0) return $sid;
    else return ERROR_DEFAULT;
}


function getStore($id){
    $db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
    $q=$db->prepare('SELECT storeID,name,contact,address,phone,fax,email,webpage,latitude,longitude,status,created,updated FROM Stores WHERE storeID=?');
    $q->bind_param("i",$id);
    $q->execute();
    $q->bind_result($storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated);
    $s=NULL;
    if($q->fetch()){
        $s=new Store($storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated);
    }
    $q->close();    
    return $s;
}

function getStoreCount($filter=NULL){
    $db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
    $sql='SELECT COUNT(*) FROM Stores';
    if($filter!=NULL) $sql.=" WHERE ".$filter;

    $q=$db->prepare($sql);
    $q->execute();
    $q->bind_result($count);
    $q->fetch();
    $q->close();    
    return $count;
}

function getStores($filter=NULL,$order=NULL,$start=0,$limit=10){
    $db = new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);

    $sql='SELECT storeID,name,contact,address,phone,fax,email,webpage,latitude,longitude,status,created,updated FROM Stores';
    if($filter!=NULL) $sql.=" WHERE ".$filter;
    if($order!=NULL) $sql.=" ORDER BY ".$order;
    if($limit>0) $sql.=' LIMIT '.$start.','.$limit;

    $q=$db->prepare($sql);
    $q->execute();
    $q->bind_result($storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated);
    $s=NULL;
    while($q->fetch()){

        if($s==NULL) $s=array();
        $store=new Store($storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated);
        $s[]=$store;
    }
    $q->close();    
    return $s;
}

?>

defines.php

<?php
define("CHARSET","utf-8");
define("BASE_URL","http://MYURL/");
define("SITE_NAME","MY SITE Maps Manager");
define("SITE_TITLE","Default Title");
define("GOOGLE_ANALYTICS_TRACKER_ID","");
define("RECAPTCHA_PUBLIC_KEY","");
define("RECAPTCHA_PRIVATE_KEY","");

define("PRIVATE_KEY","");

define("RECYCLING_BIN",-1);
define("DEFAULT_STATUS",0);
define("VERIFIED",1);
define("UNVERIFIED",2);

define("ERROR_DEFAULT",-1);

define("DB_HOST","localhost");
define("DB_ADMIN","GODADDY_DBUSER");
define("DB_PWORD","MYPASSWORD");
define("DB_NAMES","DATABASENAME");
?>

1 个答案:

答案 0 :(得分:1)

好像我们刚用完了mysql [i]技巧。

输入PDO:

使用TABLE-NAME AS更新: 商店

serialize(s::SerializationState, x::ANY<:Any) at serialize.jl:468
show(io::IO, x::ANY<:Any) at show.jl:85
methods(f::ANY<:Any) at reflection.jl:258
methods(f::ANY<:Any, t::ANY<:Any) at reflection.jl:247