dsnrixf6765 2016-05-12 07:21
浏览 36
已采纳

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

I have a storelocator for my client's website that uses a database to get all the information of the stores. This store locator works perfectly on my desktop and on my laptop local servers (localhost), but once I upload everything to my test site the store locator won't work. In a file called locate.php I include a file/class called store.php, when I go to the locate.php file on my localserver I only get notices which aren't a big deal.

enter image description here

When I go to my site, this error appears.

enter image description here

In the locate.php I also include a file called defines.php which has the information required to access the db (host, username, password, dbname). At first I thougt it could be a GoDaddy problem but I've used localhost and my website IP as the host, deleted and reuploaded the database and nothing seems to work.

Here are the files I've mentioned in this thread.

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 "
<LOCATIONS>
";


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


echo "</LOCATIONS>
";

?>

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
", 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条回答 默认 最新

  • dtxpz8785 2016-05-12 08:00
    关注

    Seems like we've just run out of mysql[i] tricks.

    ENTER PDO:

    UPDATED WITH TABLE-NAME AS: stores

    <?php
    
        // THIS IS ESSENTIALLY THE SAME STORE CLASS AS YOU HAD
        // EXCEPT THIS TIME WE CHANGED EVERYTHING CONNECTED WITH mysql[i]
        // IN OTHER WORDS; THIS IS THE PDO EQUIVALENT OF YOUR STORE CLASS:
    
    
    
    
        /***********************************************/
        /******    BEGIN STORE CLASS DEFINITION   ******/
        /***********************************************/
        class Store{
            public $storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated;
    
            //CREATE A STATIC PROPERTY TO HOLD YOUR DB-RESOURCE:
            /**@var PDO $db*/
            protected static $db;
    
            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){
                // JUST CALL THE DB CONNECTION METHOD ONCE AND USE THE HANDLE EVERYWHERE IN YOUR CODE LIKE SO:
                self::establishDBConnection();
    
                $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->created      = $created;
                $this->updated      = $updated;
                //$this->enabled=$enabled;
            }
    
            // TRY PUTTING YOUR DATABASE CONNECTION LOGIC IN ONE METHOD FOR SIMPLICITY:
            public static function establishDBConnection() {
                try {
                    if(static::$db){
                        return static::$db;
                    }else{
                        static::$db = new PDO('mysql:host='.DB_HOST.';dbname='. DB_NAMES,DB_ADMIN,DB_PWORD);
                        static::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                        return self::$db;
                    }
                } catch (PDOException $e) {
                    // IF THERE WAS AN ANY KIND OF CONNECTION ERROR, "DIE IT OUT" TO THE OUTPUT STREAM:
                    die($e->getMessage());
                }
            }
    
            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;
            }
        }
        /***********************************************/
        /*******    END STORE CLASS DEFINITION   *******/
        /***********************************************/
    
    
    
        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     = Store::establishDBConnection();
            $q      = $db->prepare('UPDATE stores SET status=:status, updated=:updated WHERE storeID=:storeID');
            $date   = date("Y-m-d H:i:s");
            $q->execute(array(
                'status'    => $status,
                'updated'   => $date,
                'storeID'   => $id,
            ));
            $q->execute();
            return 1;
        }
    
        function emptyStores(){
            $rcBin  = RECYCLING_BIN;
            $db     = Store::establishDBConnection();
            $q      = $db->prepare('DELETE FROM stores WHERE status=:rcBIN');
            $q->bindParam(':rcBIN', $rcBin);
            $q->execute();
            return 1;
        }
    
        function deleteStore($id){
            $db = Store::establishDBConnection();
            $q=$db->prepare('DELETE FROM stores WHERE storeID=:storeID');
            $q->bindParam(':storeID', $id);
            $q->execute();
            return 1;
        }
    
        function insertStore($store){
            $db             = Store::establishDBConnection();
            $store->created =date("Y-m-d H:i:s");        //overwrite dates
            $store->updated =$store->created;
    
            $sql            = 'INSERT INTO stores (name, contact, address, phone, fax, email, webpage, latitude, longitude, status, created, updated) ';
            $sql           .= 'values (:name, :contact, :address, :phone, :phone, :fax, :email, :webpage, :latitude, :longitude, :status, :created, :updated)';
    
            if($q = $db->prepare($sql)){
                $arrValues  = array(
                    "name"          =>$store->name,
                    "contact"       =>$store->contact,
                    "address"       =>$store->address,
                    "phone"         =>$store->phone,
                    "fax"           =>$store->fax,
                    "email"         =>$store->email,
                    "webpage"       =>$store->webpage,
                    "latitude"      =>$store->latitude,
                    "longitude"     =>$store->longitude,
                    "status"        =>$store->status,
                    "created"       =>$store->created,
                    "updated"       =>$store->updated
            );
    
                $q->execute($arrValues);
            }
            else{
                printf($db->errorCode());
                exit();
            }
    
            $q          = $db->prepare('SELECT storeID FROM stores WHERE name=:name AND created=:created');
            $q->bindParam(":name",      $store->name);
            $q->bindParam(":created",   $store->created);
            $objSID     = $q->fetch(PDO::FETCH_OBJ);
    
            if(strlen($objSID->storeID)>0) return $objSID->storeID;
            else return ERROR_DEFAULT;
        }
    
    
        //PRE-CONDITION: email, password, billingID, groupID must exist
        function updateStore($store){
            $db         = Store::establishDBConnection();
    
            //BEGIN ERROR CHECKING -------------------------------
    
            //END ERROR CHECKING ---------------------------------
    
            $store->updated=date("Y-m-d H:i:s");        //overwrite dates
    
            $sql        = 'UPDATE stores SET name=:name, contact=:contact, address=:address, phone=:phone, fax=:fax, email=:email, webpage=:webpage, latitude=:latitude, longitude=:longitude, status=:status, updated=:updated WHERE storeID=:storeID';
            $q          = $db->prepare($sql);
    
            $arrValues  = array(
                "name"          =>$store->name,
                "contact"       =>$store->contact,
                "address"       =>$store->address,
                "phone"         =>$store->phone,
                "fax"           =>$store->fax,
                "email"         =>$store->email,
                "webpage"       =>$store->webpage,
                "latitude"      =>$store->latitude,
                "longitude"     =>$store->longitude,
                "status"        =>$store->status,
                "created"       =>$store->created,
                "updated"       =>$store->updated,
                "storeID"       =>$store->storeID
            );
    
            $q->execute($arrValues);
    
            $q          = $db->prepare('SELECT storeID FROM stores WHERE name=:name AND created=:created');
            $q->bindParam(":name",      $store->username);
            $q->bindParam(":created",   $store->created);
            $objSID     = $q->fetch(PDO::FETCH_OBJ);
    
            if(strlen($objSID->storeID)>0) return $objSID->storeID;
            else return ERROR_DEFAULT;
        }
    
        function getStore($id){
            $db         = Store::establishDBConnection();
            $sql        = 'SELECT storeID, name, contact, address, phone, fax, email, webpagee, latitud, longitude, status, created, updated FROM stores WHERE storeID=:storeID';
            $q          = $db->prepare($sql);
            $q->bindParam(":storeID", $id);
            $q->execute();
    
            $storeObj   = $q->fetch(PDO::FETCH_OBJ);
            $s          = NULL;
    
            if($storeObj){
                $s      = new Store($storeObj->storeID, $storeObj->name, $storeObj->contact, $storeObj->address, $storeObj->phone, $storeObj->fax, $storeObj->email, $storeObj->webpage, $storeObj->latitude, $storeObj->longitude, $storeObj->status, $storeObj->created, $storeObj->updated);
            }
            return $s;
        }
    
        function getStoreCount($filter = NULL){
            $db         = Store::establishDBConnection();
            $sql        = 'SELECT COUNT(*) as count FROM stores';
            if($filter != NULL) $sql .= " WHERE " . $filter;
    
            $q          = $db->prepare($sql);
            $q->execute();
            $objCount   = $q->fetch(PDO::FETCH_OBJ);
            $count      = $objCount->count;
            return $count;
        }
    
        function getStores($filter = NULL, $order = NULL, $start = 0, $limit = 10){
            $db         = Store::establishDBConnection();
            $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();
            $arrData    = $q->fetch(PDO::FETCH_ASSOC);
            $stores     = array();
    
            foreach($arrData as $intKey=>$objData){
                $store      = new Store($objData->storeID, $objData->name, $objData->contact, $objData->address, $objData->phone, $objData->fax, $objData->email, $objData->webpage, $objData->latitude, $objData->longitude, $objData->status, $objData->created, $objData->updated);
                $stores[]   = $store;
            }
            return $stores;
        }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,