1

这是我的连接代码。错误是:

10-16 21:33:29.300: E/JSON(359):
10-16 21:33:29.300: E/JSON(359):警告: mysql_connect() [function.mysql-connect]: 未知的 MySQL 服务器主机' https' (1) in /home/shifteb/public_html/studentreg/_android_alexmed_api/include/DB_Connect.php24
行 10-16 21:33:29.300: E/JSON(359):
10-16 21:33:29.300: E/JSON(359):警告:mysql_select_db() [function.mysql-select-db]:在/home/shifteb/public_html/studentreg/_android_alexmed_api中的用户 'shifteb'@'localhost'(使用密码:NO)的访问被拒绝/include/DB_Connect.php在第26
行 10-16 21:33:29.300: E/JSON(359):
10-16 21:33:29.300: E/JSON(359):警告: mysql_select_db() [function.mysql-select-db]: 无法在/home/shifteb/public_html/studentreg/_android_alexmed_api/include/DB_Connect.php在第26
行 10-16 21:33 中建立到服务器的链接: 29.300: E/JSON(359):
10-16 21:33:29.300: E/JSON(359):警告: mysql_query() [function.mysql-query]: 拒绝访问用户'shifteb'@'localhost' (使用密码:NO) 在/home/shifteb/public_html/studentreg/_android_alexmed_api/include/DB_Functions.php中的第121
10-16 21:33:29.300: E/JSON(359):
10-16 21:33:29.300: E/JSON(359):警告:mysql_query() [function.mysql-query]:无法建立到服务器的链接/home/shifteb/public_html/studentreg/_android_alexmed_api/include/DB_Functions.php在第121
行 10-16 21:33:29.300: E/JSON(359): 拒绝用户 'shifteb'@'localhost' 的访问(使用密码:否)10-16 21:33:29.320:E/JSON 解析器(359):解析数据时出错 org.json.JSONException:值

当我尝试连接到在线时这个???

该应用程序可以完美运行,localhost但是当我更改在线服务器的 URL 并上传 php 脚本时,会出现上述错误。

这些是脚本

函数脚本

<?php

/**
 * @author ziad gamal baiomy gholmish
 * @copyright 2012
 */

class DB_Functions {

    private $db;

    //put your code here
    // constructor
    function __construct() {
        require_once 'DB_Connect.php';
        // connecting to database
        $this->db = new DB_Connect();
        $this->db->connect();
    }

    // destructor
    function __destruct() {

    }


    /**
     * 
     *function to search student 
     *  
     */

     public function searchStudent($method ,$information){


        if($method == 'e_mail'){

            $query=mysql_query(" SELECT * FROM persons WHERE `email_personal` = '$information' ");
            $no_of_rows = mysql_num_rows($query);
            if($no_of_rows > 0){

                $resultset=mysql_fetch_array($query);

                return $resultset;

            }else{

                return false;
            }
        }else if($method == 'mobile'){

            $query=mysql_query(" SELECT * FROM persons WHERE `mobile` = '$information' ");
            $no_of_rows = mysql_num_rows($query);

            if($no_of_rows > 0){


                $resultset=mysql_fetch_array($query);

                return $resultset;
            }else{

                return false;
            }


        }else if($method =='phone'){


             $query=mysql_query("SELECT * FROM persons WHERE `phone` = '$information'");
              $no_of_rows = mysql_num_rows($query);


            if($no_of_rows > 0){


                $resultset=mysql_fetch_array($query);

                return $resultset;
            }else{

                return false;
            }
        }else if($method == 'id'){

            $information= intval($information);


             $query=mysql_query("SELECT * FROM persons WHERE `id` = $information");
             $no_of_rows = mysql_num_rows($query);

            if($no_of_rows > 0){


                $resultset=mysql_fetch_array($query);

                return $resultset;
            }else{

                return false;
            }
        } 



     }


    /**
     * 
     *function to staff login 
     * 
     * 
     */


    public function staffLogin($username , $password){

        $hashed_password= sha1($password);

        $result=mysql_query("SELECT * FROM admins WHERE `username` = '$username'") or die(mysql_error());
        $no_of_rows = mysql_num_rows($result);

        if($no_of_rows > 0){
         $result = mysql_fetch_array($result);

         if($hashed_password == $result['hashed_password']){

           return $result;
         }else{

          //user not found 
          return false;
        }



   }


    }







    /**
     * 
     *function to add  staff member
     * 
     * 
     * 
     */

 public function addStaffMember($username , $password , $national_id){

        $result=mysql_query("SELECT `username` FROM admins WHERE `username` = '$username'");
         $no_of_rows = mysql_num_rows($result);
         if($no_of_rows == 0){

            $query=mysql_query("INSERT INTO persons( `national_id` ) VALUES('$national_id')");

            if($query){

                $resultset=mysql_query("SELECT max(id) FROM persons");
                $admin = mysql_fetch_array($resultset);
                $admin_id = $admin['0'];
                $admin_id= intval($admin_id);
                $hashed_password= sha1($password);
                $query=mysql_query("INSERT INTO admins (`id`, `username`, `hashed_password`) VALUES ($admin_id , '$username', '$hashed_password')");

                if($query){

                    return true;
                }else{
                    return false;

                }





            }




         }





    }





    /**
     *
     *  
     * edit student information
     * 
     * 
     */



     public function editStudentInfo($f_name ,$s_name  ,$t_name ,$l_name ,$phone ,$mobile ,$e_mail ,$city ,$department ,$street ,$building,$flat ,$id){

        $id=intval($id);

        $query=mysql_query("UPDATE persons SET `english_fName`= '$f_name' , `english_sName`= '$s_name'  , `english_tName`= '$t_name' , `english_lName`= '$l_name'  , `phone`= '$phone'  , `mobile`= '$mobile' , `city`= '$city' , `p_department`= '$department' , `street`='$street'  , `building`='$building'  , `flat`='$flat'  , `email_personal`= '$e_mail' WHERE id= $id ") or die(mysql_error());


        if($query){

            return true;

        }else{

            return false;
        }




     }

     /**
      * 
      *function to change the student password 
      * 
      * 
      */


     public function changeStudentPass($old_pass , $new_pass , $id){

        $hashed_old=sha1($old_pass);
        $hashed_new=sha1($new_pass);
        $id= intval($id);

        $query =mysql_query("SELECT * FROM students WHERE id = $id AND `hashed_password` ='$hashed_old' LIMIT 1") or die(mysql_error());
        $no_of_rows = mysql_num_rows($query);
        if($no_of_rows == 1){

            $query=mysql_query("UPDATE students SET `hashed_password` = '$hashed_new' WHERE id = $id ") or die(mysql_error());
            if($query){

                return true;

            }else{

                return true;
            }



        }










     }






 /**
  * 
  *get the user by user name and password 
  * 
  */
 public function  getUserByUserNameAndPassword($username, $password){

    $hashed_password= sha1($password); 
   $result=mysql_query("SELECT * FROM students WHERE `username` = '$username'") or die(mysql_error());
   $no_of_rows = mysql_num_rows($result);

   if($no_of_rows > 0){
    $result = mysql_fetch_array($result);

    if($hashed_password == $result['hashed_password']){

        return $result;
    }else{

        //user not found 
        return false;
    }



   }



 }









    /**
     * registeration process
     * 
     * 
     */ 

 public function registerUser($english_fName , $english_sName ,  $english_tName , $english_lName ,$phone ,$mobile ,$email_personal , $sex , $religion , $city ,$p_department, $street , $building ,$flat , $birth_date , $social , $nationality ,$seat_number ,$password){

    $query=mysql_query("select * from persons p join students s on p.id =s.id and `seat_number` =$seat_number");
    if($query){

    $resultSet=mysql_fetch_array($query);

    $file_number= $resultSet['file_number'];

    $file_number= takeTodigit($file_number);

    $username=$english_fName.".".$english_tName."12".$file_number;
    $hashed_password=sha1($password);

    $email_college=$username."@alexmed.edu.eg";
    $id=$resultSet['id'];
    $birth_date=strtotime($birth_date);
    $birth_date=date('y-m-d',$birth_date);


    $query=mysql_query("UPDATE persons set `english_fName`='$english_fName' , `english_sName`='$english_sName' , `english_tName`='$english_tName' ,`english_lName`='$english_lName',`phone`='$phone' , `mobile`='$mobile'  , `email_personal`='$email_personal' , `sex`='$sex' , `religion`='$religion' ,`city`='$city' ,`p_department`='$p_department' ,`street`='$street'  , `building`='$building' ,`flat`='$flat' ,`social`='$social' , `nationality`='$nationality' ,`email_college`='$email_college' ,`birth_date`='$birth_date'  WHERE `id`=$id ");
    $query=mysql_query("UPDATE students set `username`= '$username' ,`hashed_password`='$hashed_password' ,`active` = 1");
    $query=mysql_query("SELECT * FROM students WHERE `id`=$id ");
    if($query){

        $resultSet=mysql_fetch_array($query);
        return $resultSet;
    }else{
        return false;

    }
            }
    }




 /**
  *add new student
  *  
  * 
  */
  public function addNewStudent($fName ,$sName ,$tName,$lName,$national_id,$seat_number,$total_grades){

$issuance_of=getissuanceof($national_id);


    $query = mysql_query("INSERT INTO persons(`arabic_fName` , `arabic_sName` ,`arabic_tName` ,`arabic_lName` , `national_id` ,`issuance_of`) VALUES ('$fName' ,'$sName','$tName' ,'$lName' ,'$national_id' ,'$issuance_of')");

    if ($query) {
        //Success!
        //Generating student id:
        $resultset = mysql_query("SELECT max(id) FROM persons");
        $student = mysql_fetch_array($resultset);
        $student_id = $student['0'];
        //Inserting into the studens' table:
        $date = date('Y-m-d');

        $query = mysql_query("INSERT INTO students (`id` , `seat_number` ,`total_grades` , `file_number` , `join_date`  ) VALUES ('$student_id', '$seat_number', '$total_grades' ,'$student_id' , '$date')");

        if ($query){
              //Generating student id:  
   $student_id= intval($student_id);
     $resultset = mysql_query("SELECT `file_number` FROM students WHERE id =$student_id");
        $student = mysql_fetch_array($resultset);
      $file_number_2= $student['file_number'];
        $student_number =(int) generate_snumber($file_number_2);
        mysql_query("UPDATE students SET `student_number`=$student_number WHERE `file_number` =$file_number_2");    
        return true;
            }else{
                    die(mysql_error());

        }



            }

  }


public function search_Seat_Number($s_seat_number){


  $query = mysql_query("SELECT * FROM students WHERE `seat_number` =$s_seat_number");

  if($query){

  if(mysql_num_rows($query) == 0){


  return false;

  }else{

    return true;
  }

  }else{

    return false;
  }

  }
 }

function generate_snumber($file_number){

      $file_number= strval($file_number);
      if(strlen($file_number) == 1){


        $file_number= "000".$file_number;
      }
      else if(strlen($file_number) == 2){


        $file_number= "00".$file_number;
      }

      else if(strlen($file_number) == 3){

        $file_number = "0".$file_number;
      }

      $student_number= "12".$file_number;
      return $student_number;



  }

  function takeTodigit($file_number){

    if(strlen($file_number) == 1){
 $file_number = "0".$file_number;
       }
       if(strlen($file_number) == 2 )
       {

        $file_number =$file_number;
       }

       if(strlen($file_number) ==3){

        $file_number = substr($file_number, -2);

       }
       if(strlen($file_number) == 4){

        $file_number= substr($file_number, -2);
       }
       return $file_number;


  }



  function getissuanceof($national_id){



  $issuance_of=$national_id[7].$national_id[8];
  return $issuance_of;     
    }










?>

配置脚本是:

<?php

/**
 * @author ziad gamal baiomy gholmish
 * @copyright 2012
 */
/**
 * Database config variables
 */
define("DB_HOST", "https://supremecenter10.se/pma/index.php?token=a8aa13f9715f82765b6d101b2b1a43ff");
define("DB_USER", "ultratech_mobdb");
define("DB_PASSWORD", "******"// the password );
define("DB_DATABASE", "******//the username here ");

?>

连接脚本:

<?php

/**
 * @author ziad gamal baiomy gholmish
 * @copyright 2012
 */


    class DB_Connect {

        // constructor
        function __construct() {

        }

        // destructor
        function __destruct() {
            // $this->close();
        }

        // Connecting to database
        public function connect() {
            require_once 'config.php';
            // connecting to mysql
            $con = mysql_connect("https://supremecenter10.se/pma/index.php?token=a8aa13f9715f82765b6d101b2b1a43ff", "username" ,"password");
            // selecting database
            mysql_select_db("https://supremecenter10.se/pma/index.php?token=a8aa13f9715f82765b6d101b2b1a43ff");

            // return database handler
            return $con;
        }

        // Closing database connection
        public function close() {
            mysql_close();
        }

    }




    ?>
4

1 回答 1

0

看来您可能是关于 SO: Null Pointer Exception while retrieving JSON Object的这个问题中讨论的相同问题。

看看上面链接中提供的解决方案。我希望这有帮助。

于 2012-10-15T04:24:44.767 回答